[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Working with regular expressions and "$"?

Joshua Muheim

11/23/2007 1:51:00 PM

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
--
Posted via http://www.ruby-....

3 Answers

Eric I.

11/23/2007 3:15:00 PM

0

On Nov 23, 8:50 am, Joshua Muheim <fo...@josh.ch> wrote:
> 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://Lea...

Jano Svitok

11/23/2007 3:28:00 PM

0

On Nov 23, 2007 4:15 PM, Eric I. <rubytraining@gmail.com> wrote:
> On Nov 23, 8:50 am, Joshua Muheim <fo...@josh.ch> wrote:
> > 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.

http://www.zenspider.com/Languages/Ruby/QuickR...

Joshua Muheim

11/23/2007 3:29:00 PM

0

Thanks a lot :-)
--
Posted via http://www.ruby-....