Okay. Let me tell you then, what I understood from it.
When first `X` found string has been splitted as ["a","Xb"]. Now on the
second unprocessed substring "Xb", again 'X' matched, so it has benn
splitted as ["","b"]. And finally `["a", "", "b"]`. Am I correct ?
Roughly. I can't say whether it is actually done that way but the
rule is simple: String#split will return everything between matches of
separator regexp.
You can imagine working like this
irb(main):001:0> def split s, re
irb(main):002:1> a =
irb(main):003:1> pos = 0
irb(main):004:1> s.scan(re) {|m| n = $`.length; a << s[pos...n]; pos =
n + m.length}
irb(main):005:1> a << s[pos..-1]
irb(main):006:1> return a
irb(main):007:1> end
=> nil
irb(main):008:0> split "aXXb", /X/
=> ["a", "", "b"]
Cheers
robert
···
On Tue, Mar 11, 2014 at 1:48 PM, Arup Rakshit <lists@ruby-forum.com> wrote:
Robert Klemme wrote in post #1139487:
On Tue, Mar 11, 2014 at 1:03 PM, Arup Rakshit <lists@ruby-forum.com>
Okay. Let me tell you then, what I understood from it.
When first `X` found string has been splitted as ["a","Xb"]. Now on the
second unprocessed substring "Xb", again 'X' matched, so it has benn
splitted as ["","b"]. And finally `["a", "", "b"]`. Am I correct ?