Albert Schlef wrote:
> I want to extract an "id" parameter from the URL. I use the following
> code:
>
>   url = "http://example.com/id=12345"
>   id = url[ /(?<=id=)(\d+)/ ]
>   puts id
>
> But I get a SyntaxError telling me "undefined (?...) sequence".
>
> Why?
>   
I've lately been making excellent use of the  MatchData class, so here's 
my solution:

irb(main):012:0> m = /\d+/.match("http://example.com/id=12345")
=> #<MatchData "12345">
irb(main):013:0> m[0]
=> "12345"

In other situations, some of the various class methods can be useful:

irb(main):014:0> m.pre_match
=> "http://example.com/id="
irb(main):015:0>

There's a #post_match method also...and more.

t.

-- 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc / tomcloyd.com >> (email)
<< TomCloyd.com >> (website) 
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~