# Matchdata#end one character after match?

**URL:** <https://rubytalk.org/t/matchdata-end-one-character-after-match/13760>\
**Category:** ruby-talk\
**Created:** [23 September 2004 17:33 UTC](https://rubytalk.org/t/matchdata-end-one-character-after-match/13760 "2004-09-23T17:33:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [23 September 2004 17:33 UTC](https://rubytalk.org/t/matchdata-end-one-character-after-match/13760/1 "2004-09-23T17:33:58Z")

</div>

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.  
> / \ [transami@runbox.com](mailto:transami@runbox.com)
> 
> I don't give a damn for a man that can only spell a word one way.  
> -Mark Twain

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [23 September 2004 19:44 UTC](https://rubytalk.org/t/matchdata-end-one-character-after-match/13760/2 "2004-09-23T19:44:32Z")

</div>

"trans. (T. Onoma)" \<transami@runbox.com\> schrieb im Newsbeitrag news:200409231333.49887.transami@runbox.com...

> 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

&nbsp;&nbsp;&nbsp;&nbsp;robert
