Newbie regexp question

Thanks! So exciting!

···

-----Original Message-----
From: "Gregory Brown" <gregory.t.brown@gmail.com>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: 7/5/2007 6:45 PM
Subject: Re: Newbie regexp question

On 7/5/07, Skt <scottjourand@gmail.com> wrote:

Newbs here, decided to take today to learn regular expression.

What i want to do is take a sentence and just pull two things from it. Example:

"My address is 68 Ohio"

I want to pull address and 68 from the sentence but that pesky is is getting in my way(or im too newb)

"My address is 68 ohio" =~ /\w{7}\d{2}/ is what i tried but continuous nils. Any help?

m = "My address is 68 Ohio".match(/(\w{7}).*(\d{2})/)

=> #<MatchData:0x33c17c>

m[1]

=> "address"

m[2]

=> "68"

But what that actually says is 'Match a word 7 characters long,
followed by zero or more matches of any character (except newline),
then match two digits.

If you really wanted to pull address and 68, you'd want:

m = "My address is 68 Ohio".match(/(address).*(68)/)

=> #<MatchData:0x314438>

m[1]

=> "address"

m[2]

=> "68"

Hope that helps.