[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Regex query

Manoj P M

1/10/2007 10:32:00 AM

Hi,

A Simple question on regular expression in ruby. Some can make me
understand the below code snippets. I was under the impression that
both these statement would give the same answer. But it doesnt. Why ?

irb(main):001:0> 'banana' =~ /(an)*/
=> 0
irb(main):002:0> 'banana' =~ /(an)+/
=> 1

-Manjo

1 Answer

Luis Parravicini

1/10/2007 11:02:00 AM

0

On 1/10/07, Manoj P M <manjo.pm@gmail.com> wrote:
> A Simple question on regular expression in ruby. Some can make me
> understand the below code snippets. I was under the impression that
> both these statement would give the same answer. But it doesnt. Why ?
>
> irb(main):001:0> 'banana' =~ /(an)*/
> => 0

In this case you are looking for '', 'an', 'anan', 'ananan' and so on.
So it matches at the beginning of the string (index 0) with the empty
string.


Luis