[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

rindex with regexp

T. Onoma

12/28/2004 4:10:00 AM

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.


2 Answers

Yukihiro Matsumoto

12/28/2004 4:23:00 AM

0

Hi,

In message "Re: rindex with regexp"
on Tue, 28 Dec 2004 13:09:58 +0900, "trans. (T. Onoma)" <transami@runbox.com> 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.


T. Onoma

12/28/2004 4:55:00 AM

0

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!