# Largest Regex match possible

**URL:** <https://www.ruby-forum.com/t/largest-regex-match-possible/143845>\
**Category:** Ruby\
**Created:** [July 23, 2008, 7:40am UTC](https://www.ruby-forum.com/t/largest-regex-match-possible/143845 "2008-07-23T07:40:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 23, 2008, 7:40am UTC](https://www.ruby-forum.com/t/largest-regex-match-possible/143845/1 "2008-07-23T07:40:43Z")

</div>

In the example below I’d like to match ‘what is’ and ‘foo bar’. Any  
ideas?

‘what is foo bar’ =~ /(._)\s_(foo bar|bar)/ =\> 0  
$1 =\> "what is foo "  
$2 =\> “bar”

Thanks!

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 23, 2008, 8:01am UTC](https://www.ruby-forum.com/t/largest-regex-match-possible/143845/2 "2008-07-23T08:01:47Z")

</div>

Hi,

2008/7/23 gsterndale [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> In the example below I’d like to match ‘what is’ and ‘foo bar’. Any  
> ideas?
> 
> ‘what is foo bar’ =~ /(._)\s_(foo bar|bar)/ =\> 0  
> $1 =\> "what is foo "  
> $2 =\> “bar”
> 
> Thanks!

Try this:

‘what is foo bar’ =~ /(.\*?)\s+(foo bar|bar)/

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 23, 2008, 8:55am UTC](https://www.ruby-forum.com/t/largest-regex-match-possible/143845/3 "2008-07-23T08:55:37Z")

</div>

On Jul 23, 1:55 am, Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Try this:
> 
> ‘what is foo bar’ =~ /(.\*?)\s+(foo bar|bar)/
> 
> Regards,
> 
> Park H.

Good stuff. Thanks Park!
