Working with regular expressions and "$"?

J

Joshua Muheim

Hi all

I remember to have read somewhere that the matching results of a regular
expression match like

string1 =~ /some_expression/

is stored in "$". I couldn't find documentation related to this (it's a
little hard to search google for "ruby regexp $"), so maybe someone has
some information for me? :)

Thanks
Josh
 
E

Eric I.

Hi all

I remember to have read somewhere that the matching results of a regular
expression match like

string1 =~ /some_expression/

is stored in "$". I couldn't find documentation related to this (it's a
little hard to search google for "ruby regexp $"), so maybe someone has
some information for me? :)

If you have the 2nd edition of the pick-axe book, in chapter 22,
there's a section called "Variables and Constants" which give a slew
of variables.

I don't want to type them all in. But it looks like you're after
either $&, which provides the matching string, or $~, which provides
the MatchData object that describes the match.

Eric

====

Are you interested in on-site Ruby training that's been highly
reviewed by former students? http://LearnRuby.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top