# Regexp help please

**URL:** <https://www.ruby-forum.com/t/regexp-help-please/142259>\
**Category:** Ruby\
**Created:** [July 5, 2008, 11:33am UTC](https://www.ruby-forum.com/t/regexp-help-please/142259 "2008-07-05T11:33:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PDTCT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4af34b/32.png) [@PDTCT](https://www.ruby-forum.com/u/PDTCT)\
**Post date:** [July 5, 2008, 11:33am UTC](https://www.ruby-forum.com/t/regexp-help-please/142259/1 "2008-07-05T11:33:40Z")

</div>

Hi All,

I am trying to extract quoted text fromlines in a file. Assume I have  
read in a line as follows

type “this piece of text” into field called “search field”

I then want to extract the two pieces of quoted text from this line.  
I’m halfway there with this  
line =~ /(".\*?")/  
this will match the first piece of quoted text, which I can access  
with $1. I’m having trouble getting the match to carry on & match the  
next piece of quoted text.

Any help greatly appreciated 🙂

Many Thanks

Paul

---

<div class="post-metadata">

**Author:** ![PDTCT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4af34b/32.png) [@PDTCT](https://www.ruby-forum.com/u/PDTCT)\
**Post date:** [July 5, 2008, 11:43am UTC](https://www.ruby-forum.com/t/regexp-help-please/142259/2 "2008-07-05T11:43:03Z")

</div>

453/22 \> irb  
irb(main):001:0\> a=%\<“first” and “second”\>  
=\> “"first" and "second"”  
irb(main):002:0\> a.scan /“.\*?”/  
=\> [“"first"”, “"second"”]  
irb(main):003:0\>

HTH  
Robert

–  
[http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

AALST (n.) One who changes his name to be further to the front  
D.Adams; The Meaning of LIFF

---

<div class="post-metadata">

**Author:** ![PDTCT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4af34b/32.png) [@PDTCT](https://www.ruby-forum.com/u/PDTCT)\
**Post date:** [July 5, 2008, 1:23pm UTC](https://www.ruby-forum.com/t/regexp-help-please/142259/3 "2008-07-05T13:23:42Z")

</div>

Or:

line=%\<“first” and “second”\>  
line =~ /("._?")[^"]_(".\*?")/

puts $1 # =\> “first”  
puts $2 # =\> “second”

The [^"]\* means “zero or more characters that aren’t a doublequote  
character”.

Dave

---

<div class="post-metadata">

**Author:** ![PDTCT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4af34b/32.png) [@PDTCT](https://www.ruby-forum.com/u/PDTCT)\
**Post date:** [July 5, 2008, 2:35pm UTC](https://www.ruby-forum.com/t/regexp-help-please/142259/4 "2008-07-05T14:35:52Z")

</div>

Thanks Robert, that was exactly what I was looking for. I knew there  
had to be a simple way to do it in Ruby. I love Ruby!!

Paul
