[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

largest Regex match possible

gsterndale

7/23/2008 5:38:00 AM

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!
2 Answers

Heesob Park

7/23/2008 5:56:00 AM

0

Hi,

2008/7/23 gsterndale <gsterndale@gmail.com>:
> 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 Heesob

gsterndale

7/23/2008 6:51:00 AM

0

On Jul 23, 1:55 am, Heesob Park <pha...@gmail.com> wrote:
> Hi,
>
> 2008/7/23 gsterndale <gsternd...@gmail.com>:> 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 Heesob

Good stuff. Thanks Park!