On Thu, Dec 4, 2008 at 8:09 PM, David A. Black <dblack / rubypal.com> wrote:

> Try this:
>
>  a.split(/(?=an?\b|the\b)/i)

Neat, thanks. I understand how lookaheads work when it comes to
matching a regex,
but it's still not clear to me why split works with the lookahead.
Isn't the match of the lookahead a 0-width string?

irb(main):001:0> a = "abcxxxabcxxxabcxxx"
=> "abcxxxabcxxxabcxxx"
irb(main):006:0> a.match(/(?=abc)/)[0]
=> ""
irb(main):007:0> a =~ /(?=abc)/
=> 0

Then, how does split knows where to start the next search?

Thanks,

Jesus.