[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Regex Question

seebs

7/24/2007 7:09:00 PM

In message <1185303847.407283.279370@x35g2000prf.googlegroups.com>, seijin@gmai
l.com writes:
>Oh, I see. So using the "*" with just one ... errr... thing will
>never match it? "banana" =~ /a*/ will always be 0 but "banana" =~ /
>a*n/ will be 1 (one) ?

Both will match.

The thing to understand is that /X*/ always matches successfully
no matter whether X is anchored or not, is long or a single character,
or what, simply because it can always match the empty string.

If it matches the beginning of a word, it will match greedily, but
it won't go looking for a longer match later instead of taking the first
match it finds.

-s