# Regexp help needed

**URL:** <https://www.ruby-forum.com/t/regexp-help-needed/93128>\
**Category:** Ruby\
**Created:** [April 27, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/regexp-help-needed/93128 "2007-04-27T23:51:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 27, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/regexp-help-needed/93128/1 "2007-04-27T23:51:27Z")

</div>

Hey All,

I need to parse lines that look like this:

1 'Not qualified' 2 'Overquota' 3 'Qualified'/ 1 'SSI' 2 'Mall Facility'/ 1 'Real Interview' 2 'Practice Interview'/

So I’ve got N sets of \<\>\<\>\<\> on  
each line. I want to grab each of the digits & labels, but I’m having  
trouble w/the repetition stuff. Below is a simple script that doesn’t  
work–it grabs the first set, but seems to ignore the rest.

str = “1 ‘Not qualified’ 2 ‘Overquota’ 3 ‘Qualified’”  
rgx = /((\d+)\s+(’[^’]+?’))+/i  
m = rgx.match(str)  
unless m.nil?  
m.captures.each {|c| puts©}  
end

Can anybody throw me a regex clue here?

Thanks!

- Roy

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 28, 2007, 12:10am UTC](https://www.ruby-forum.com/t/regexp-help-needed/93128/2 "2007-04-28T00:10:29Z")

</div>

Hey Roy,  
On Sat, Apr 28, 2007 at 06:50:10AM +0900, removed\_email\_address@domain.invalid wrote:

> So I’ve got N sets of \<\>\<\>\<\> on
> 
> Can anybody throw me a regex clue here?

You might want to try the scan method:

str = “1 ‘Not qualified’ 2 ‘Overquota’ 3 ‘Qualified’”

str.scan(/(\d+)\s+(’[^’]+’)+/).each do |match|  
p match  
end

Hope that helps!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 28, 2007, 12:12am UTC](https://www.ruby-forum.com/t/regexp-help-needed/93128/3 "2007-04-28T00:12:29Z")

</div>

Perhaps a little something like this:

str = “1 ‘Not qualified’ 2 ‘Overquota’ 3 ‘Qualified’”  
rgx = /((\d+)\s+(’[^’]+?’))+/i  
m = str.scan(rgx)  
m.each do |match|  
puts match.first  
end

Duane J.  
(canadaduane)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 28, 2007, 12:15am UTC](https://www.ruby-forum.com/t/regexp-help-needed/93128/4 "2007-04-28T00:15:29Z")

</div>

On 4/27/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So I’ve got N sets of \<\>\<\>\<\> on

r = %r/(\d+)\s+(‘[^’]\*')/  
s = “1 ‘Not qualified’ 2 ‘Overquota’ 3 ‘Qualified’”

s.scan(r) #=\> [[“1”, “‘Not qualified’”], [“2”,  
“‘Overquota’”], [“3”, “‘Qualified’”]]

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 28, 2007, 12:26am UTC](https://www.ruby-forum.com/t/regexp-help-needed/93128/5 "2007-04-28T00:26:30Z")

</div>

Ah–that’s the magic! Thanks guys!

-Roy
