"Simon Strandgaard" <neoneye / adslhome.dk> schrieb im Newsbeitrag news:20040531104155.074a42b0.neoneye / adslhome.dk... > 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. But what about: >> 'ab'.split(/\D+/) => [] You would at least expect one empty string in the result since there is at least one separator. This strikes me as odd. robert