# Something like eregi() in ruby?

**URL:** <https://www.ruby-forum.com/t/something-like-eregi-in-ruby/112798>\
**Category:** Ruby\
**Created:** [August 23, 2007, 11:49am UTC](https://www.ruby-forum.com/t/something-like-eregi-in-ruby/112798 "2007-08-23T11:49:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![schu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@schu](https://www.ruby-forum.com/u/schu)\
**Post date:** [August 23, 2007, 11:49am UTC](https://www.ruby-forum.com/t/something-like-eregi-in-ruby/112798/1 "2007-08-23T11:49:08Z")

</div>

hi people!

i can’t info on that - is there anything comparable to the  
functionality of ereg() or preg\_match() of PHP under ruby?

thx in advance  
S

---

<div class="post-metadata">

**Author:** ![schu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@schu](https://www.ruby-forum.com/u/schu)\
**Post date:** [August 23, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/something-like-eregi-in-ruby/112798/2 "2007-08-23T13:45:57Z")

</div>

Schu wrote:

> hi people!
> 
> i can’t info on that - is there anything comparable to the  
> functionality of ereg() or preg\_match() of PHP under ruby?
> 
> thx in advance  
> S

Look at the methods String and Regexp provide.  
Like String#match, Regexp#match, String#=~, Regexp#=~, String#scan,  
String#sub, String#gsub.  
Also take a look at MatchData (returned by the #match methods).  
For case insensitivity, use the i switch, example: /foo/i, or %r{foo}i  
(/regex/ is a regex literal which does the same as Regexp.new(‘regex’),  
%r{regex} is just a different way to write it).

Regards  
Stefan

---

<div class="post-metadata">

**Author:** ![schu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@schu](https://www.ruby-forum.com/u/schu)\
**Post date:** [August 23, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/something-like-eregi-in-ruby/112798/3 "2007-08-23T16:07:46Z")

</div>

On 23 août, 11:23, Schu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi people!
> 
> i can’t info on that - is there anything comparable to the  
> functionality of ereg() or preg\_match() of PHP under ruby?
> 
> thx in advance  
> S

Hi,

Of course :

I don’t know PHP but I think match is the closer equivalent of ereg

re.match(string) or string.match(re) =\> object matchdata

This object matchdata has methods like pre\_match and post\_match.

Come

---

<div class="post-metadata">

**Author:** ![schu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@schu](https://www.ruby-forum.com/u/schu)\
**Post date:** [August 23, 2007, 4:15pm UTC](https://www.ruby-forum.com/t/something-like-eregi-in-ruby/112798/4 "2007-08-23T16:15:49Z")

</div>

> Of course :
> 
> I don’t know PHP but I think match is the closer equivalent of ereg
> 
> re.match(string) or string.match(re) =\> object matchdata
> 
> This object matchdata has methods like pre\_match and post\_match.

thanks a lot, that’s exactly what i was looking for!
