# String#split and capturing delimiters

**URL:** <https://www.ruby-forum.com/t/string-split-and-capturing-delimiters/178178>\
**Category:** Ruby\
**Created:** [October 30, 2009, 8:45am UTC](https://www.ruby-forum.com/t/string-split-and-capturing-delimiters/178178 "2009-10-30T08:45:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [October 30, 2009, 8:45am UTC](https://www.ruby-forum.com/t/string-split-and-capturing-delimiters/178178/1 "2009-10-30T08:45:20Z")

</div>

Since what version of Ruby does “String#split /(whatever)/” returns the  
delimiters in the result?

In other words, since what version it’s possible, as in Perl, to put  
parentheses is the regexp and have them returned?

(I’m using Ruby 1.8)

I’ve looked into the documentation of String#split, but it doens’t  
mention this feature, so I’m asking you.

That's exasperating. In the past I used to love Ruby. But nowadays you have to be a lawyer, or a historion, if you want to use it. There are several "version 1.8" with different APIs and whenever you want to use some feature you're worried perhaps it won't be supported by whoever runs your program. "Writing Ruby is like writing literature" my foot.

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [October 30, 2009, 9:00am UTC](https://www.ruby-forum.com/t/string-split-and-capturing-delimiters/178178/2 "2009-10-30T09:00:16Z")

</div>

Hi,

In message “Re: String#split and capturing delimiters”  
on Fri, 30 Oct 2009 16:45:23 +0900, Albert S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|Since what version of Ruby does “String#split /(whatever)/” returns the  
|delimiters in the result?

From the beginning. It has been there at least since 0.49 back in  
July 1994, which is the oldest source code available at hand, far  
before the public release.

|That’s exasperating. In the past I used to love Ruby. But nowadays you  
|have to be a lawyer, or a historion, if you want to use it.

That’s unfortunate. I guess you’ve changed the attitude toward the  
language, nowadays.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [October 30, 2009, 9:48am UTC](https://www.ruby-forum.com/t/string-split-and-capturing-delimiters/178178/3 "2009-10-30T09:48:03Z")

</div>

Yukihiro M. wrote:

> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> |Since what version of Ruby does “String#split /(whatever)/” returns the  
> |delimiters in the result?
> 
> From the beginning. It has been there at least since 0.49 back in  
> July 1994, which is the oldest source code available at hand, far  
> before the public release.

Thanks!

(It’s just that not very long ago I’ve read in some CHNAGELOG something  
along the line of “now String#split behaves more like Perl’s”, and this  
caused me to have a second thought before using the “capturing”  
feature.)

> |That’s exasperating. In the past I used to love Ruby. But nowadays you  
> |have to be a lawyer, or a historion, if you want to use it.
> 
> That’s unfortunate. I guess you’ve changed the attitude toward the  
> language, nowadays.

I wish to apologize for my rant. What I wrote was merely “air venting”;  
it wasn’t actually about Ruby. I utilized the fact that Ruby-talk isn’t  
only for getting technical answers but also for “hugs” in times of need,  
if you know what I mean. I didn’t mean for what I wrote to be taken  
[very] seriously. Sorry. Well, I hope whis shall be a lesson for me.

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [October 30, 2009, 2:27pm UTC](https://www.ruby-forum.com/t/string-split-and-capturing-delimiters/178178/4 "2009-10-30T14:27:19Z")

</div>

Albert S. wrote:

> I wish to apologize for my rant. What I wrote was merely “air venting”;  
> it wasn’t actually about Ruby. I utilized the fact that Ruby-talk isn’t  
> only for getting technical answers but also for “hugs” in times of need,  
> if you know what I mean. I didn’t mean for what I wrote to be taken  
> [very] seriously. Sorry. Well, I hope whis shall be a lesson for me.

When you scream in your own room, your neighbors hear you.  
When you scream on the internet, Matz hears you too.

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [October 30, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/string-split-and-capturing-delimiters/178178/5 "2009-10-30T19:56:04Z")

</div>

On Fri, Oct 30, 2009 at 4:48 AM, Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I wish to apologize for my rant. What I wrote was merely “air venting”;  
> it wasn’t actually about Ruby. I utilized the fact that Ruby-talk isn’t  
> only for getting technical answers but also for “hugs” in times of need,  
> if you know what I mean.

I do, here you go XOXOXOXO 😉

I didn’t mean for what I wrote to be taken

> [very] seriously.

just a little serious then?

Sorry. Well, I hope whis shall be a lesson for me.

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Kind Regards,  
Rajinder Y.

[http://DevMentor.org](http://DevMentor.org)

Do Good! - Share Freely, Enrich and Empower people to Transform their  
lives.
