Matchdata#end one character after match?

T

trans. (T. Onoma)

I know this is probably just the way it works, but I was a bit antiPOLSed.

irb(main):016:0> md = /X/.match("yzXrb")
=> #<MatchData:0x402fbe8c>
irb(main):018:0> p md.begin(0)
2
=> nil
irb(main):017:0> p md.end(0)
3
=> nil

3 and not 2?

--
( o _ カラãƒ
// T. / trans.
/ \ (e-mail address removed)

I don't give a damn for a man that can only spell a word one way.
-Mark Twain
 
R

Robert Klemme

trans. (T. Onoma) said:
I know this is probably just the way it works, but I was a bit antiPOLSed.

irb(main):016:0> md = /X/.match("yzXrb")
=> #<MatchData:0x402fbe8c>
irb(main):018:0> p md.begin(0)
2
=> nil
irb(main):017:0> p md.end(0)
3
=> nil

3 and not 2?

Yes, and it's reasonable: all sorts of computations are a lot easier with
this convention. For example:
length = m.end(0) - m.begin(0)
empty = m.begin(0) == m.end(0)
etc.

All libs that deal with sub sequences reasonable do it this way. *I* would
have been surprised if it was otherwise.

Regards

robert
 

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,774
Messages
2,569,596
Members
45,131
Latest member
IsiahLiebe
Top