--20cf307d04aaf620a304aa551ea9
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

2011/8/12 Bartosz Dziewoski <matma.rex / gmail.com>

> I don't think I understand; "putting it back in" doesn't matter here,
> nor does using gsub instead of, say, scan.
>
> irb(main):006:0> s = 'ababababa'
> => "ababababa"
> irb(main):007:0> s.gsub(/aba/, 'aca')
> => "acabacaba"
> irb(main):008:0> s.scan /aba/
> => ["aba", "aba"]
> irb(main):011:0> s.scan /(?=aba)/
> => ["", "", "", ""]
>
> Note how the first scan returned two results, even though you can
> clearly see "aba" appears in the string 4 times. Note how the second
> returned 4 matches (even if they're all empty). Once a character is
> matched, regex engine moves forward, discarding everything up to the
> end of match, inclusive.
>
> -- Matma Rex
>
>

If that's the case then I have absolutely no idea why either of my
expressions work.

In my initial testing I wasn't returning the separator + match_group +
separator pattern from the gsub block and it was skipping the second
encapsulated string when there were two in a row.

At any rate, why does (\s|$) match differently from (?=\s|$)

--20cf307d04aaf620a304aa551ea9--