Regex query

Discussion in 'Ruby' started by Manoj P M, Jan 10, 2007.

  1. Manoj P M

    Manoj P M Guest

    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
     
    Manoj P M, Jan 10, 2007
    #1
    1. Advertising

  2. On 1/10/07, Manoj P M <> 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
     
    Luis Parravicini, Jan 10, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    712
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,634
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    601
  4. Xah Lee
    Replies:
    1
    Views:
    944
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    770
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page