From: Simon Strandgaard Date: 2004-05-31T17:46:22+09:00 Subject: Re: [bug] String#split returns extra empty string Simon Strandgaard wrote: > While extending my own regexp-engine with a split method, > I discovered something odd about Ruby's split. > > irb(main):001:0> 'ab1ab'.split(/\D+/) > => ["", "1"] > > Its asymmetric, it has a special case for eliminating > the last empty string.. but apparently not the first empty string. > > I would have expected above to be symmetric, and output: > => ["1"] > [10 minutes of experimenting later] I wasn't aware that Ruby inserts subcaptures this way. irb(main):001:0> "ab2cd3".split(/(\D+)/, 2) => ["", "ab", "2cd3"] Because of subcapture insertion, it make sense to keep the first empty string. I withdraw this bug-report. -- Simon Strandgaard