rindex with regexp

Discussion in 'Ruby' started by trans. (T. Onoma), Dec 28, 2004.

  1. Using rindex with a regexp would appear to undermine greediness.

    irb(main):012:0> "a--b--c".rindex(/[-]+/)
    => 5
    irb(main):013:0> p $~.begin(0)
    5
    => nil
    irb(main):014:0> p $~.end(0)
    6
    => nil

    I would expect the 5 to be a 4.

    T.
     
    trans. (T. Onoma), Dec 28, 2004
    #1
    1. Advertising

  2. Hi,

    In message "Re: rindex with regexp"
    on Tue, 28 Dec 2004 13:09:58 +0900, "trans. (T. Onoma)" <> writes:

    |Using rindex with a regexp would appear to undermine greediness.
    |
    |irb(main):012:0> "a--b--c".rindex(/[-]+/)
    |=> 5
    |irb(main):013:0> p $~.begin(0)
    |5

    |I would expect the 5 to be a 4.

    rindex is as lazy as me not to seek longest match.

    matz.
     
    Yukihiro Matsumoto, Dec 28, 2004
    #2
    1. Advertising

  3. On Monday 27 December 2004 11:22 pm, Yukihiro Matsumoto wrote:
    | rindex is as lazy as me not to seek longest match.
    |
    | matz.

    lol :)

    T.

    P.S. BTW, I recently saw a picture of you. A Most Excellent Beard!
     
    trans. (T. Onoma), Dec 28, 2004
    #3
    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. Hadmut Danisch

    Array::index and rindex operator

    Hadmut Danisch, Jul 5, 2004, in forum: Ruby
    Replies:
    22
    Views:
    332
    David A. Black
    Jul 8, 2004
  2. STEPHEN BECKER I V

    rindex with array of arrays

    STEPHEN BECKER I V, Sep 28, 2004, in forum: Ruby
    Replies:
    3
    Views:
    214
    STEPHEN BECKER I V
    Sep 29, 2004
  3. Greg Hurrell
    Replies:
    4
    Views:
    181
    James Edward Gray II
    Feb 14, 2007
  4. Joao Silva
    Replies:
    16
    Views:
    407
    7stud --
    Aug 21, 2009
  5. Paul.Lee.1971

    Rindex used to find end of a string

    Paul.Lee.1971, Feb 28, 2007, in forum: Perl Misc
    Replies:
    4
    Views:
    128
    Dr.Ruud
    Mar 11, 2007
Loading...

Share This Page