# Working with regular expressions and "$"?

**URL:** <https://www.ruby-forum.com/t/working-with-regular-expressions-and/121080>\
**Category:** Ruby\
**Created:** [November 23, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/working-with-regular-expressions-and/121080 "2007-11-23T14:50:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [November 23, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/working-with-regular-expressions-and/121080/1 "2007-11-23T14:50:33Z")

</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

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [November 23, 2007, 4:15pm UTC](https://www.ruby-forum.com/t/working-with-regular-expressions-and/121080/2 "2007-11-23T16:15:29Z")

</div>

On Nov 23, 8:50 am, Joshua M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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://LearnRuby.com](http://LearnRuby.com)

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [November 23, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/working-with-regular-expressions-and/121080/3 "2007-11-23T16:29:07Z")

</div>

Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [November 23, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/working-with-regular-expressions-and/121080/4 "2007-11-23T16:29:33Z")

</div>

On Nov 23, 2007 4:15 PM, Eric I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

> **[Ruby | zenspider.com | by ryan davis](https://www.zenspider.com/ruby/)**
>
> Ruby facts, opinions, source code, links, and stuff.
