in reply to Regexp - groupings

The first split shall use /(a|b)+/ as a delimiter.

From the first matching substring 'aba' in $x the first matching character is 'a', which is captured and goes into the result array. The other characters 'ba' are also part of the delimiter, but not captured, so they don't go into the result array. If you expected '+' to multiply the captures in one delimiter, you were wrong. All captures are determined during the compilation of the regex.

The second matching substring is 'ba'. Again the first character is captured ('b'), and the following 'a' is ignored.

The second split does not capure anything from the delimiter, so 'a' and 'b' from the result of the first split are not present here.