rindex with regexp

T

trans. (T. Onoma)

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.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: rindex with regexp"

|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.
 
T

trans. (T. Onoma)

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top