# Working with regular expressions and "$"?

**URL:** <https://rubytalk.org/t/working-with-regular-expressions-and/42444>\
**Category:** ruby-talk\
**Created:** [23 November 2007 13:50 UTC](https://rubytalk.org/t/working-with-regular-expressions-and/42444 "2007-11-23T13:50:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua\_Muheim](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Joshua\_Muheim](https://rubytalk.org/u/Joshua_Muheim)\
**Post date:** [23 November 2007 13:50 UTC](https://rubytalk.org/t/working-with-regular-expressions-and/42444/1 "2007-11-23T13:50:32Z")

</div>

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-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Eric\_I2](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@Eric\_I2](https://rubytalk.org/u/Eric_I2)\
**Post date:** [23 November 2007 15:15 UTC](https://rubytalk.org/t/working-with-regular-expressions-and/42444/2 "2007-11-23T15:15:00Z")

</div>

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

> **···**
>
> 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? 🙂
> 
> ====
> 
> Are you interested in on-site Ruby training that's been highly  
> reviewed by former students? [http://LearnRuby.com](http://LearnRuby.com)

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [23 November 2007 15:28 UTC](https://rubytalk.org/t/working-with-regular-expressions-and/42444/3 "2007-11-23T15:28:19Z")

</div>

[http://www.zenspider.com/Languages/Ruby/QuickRef.html#18](http://www.zenspider.com/Languages/Ruby/QuickRef.html#18)

> **···**
>
> 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.

---

<div class="post-metadata">

**Author:** ![Joshua\_Muheim](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Joshua\_Muheim](https://rubytalk.org/u/Joshua_Muheim)\
**Post date:** [23 November 2007 15:29 UTC](https://rubytalk.org/t/working-with-regular-expressions-and/42444/4 "2007-11-23T15:29:06Z")

</div>

Thanks a lot 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
