I'm attempting to write a Perl 6 regex for this code-golf challenge that splits a string with the rules:
- Sequences of the same character with length 3 or less will be grouped together
- But 4 or more will result in the first two being grouped before checking the rest
For example:
66667888 -> '66', '66, '7', '888'
19999999179 -> '1', '99', '99', '999', '1', '7', '9'
I thought the regex m:g/(.)[$0$0<!$0>|$0?]/
would work, but using a capture in the negative lookahead seems to break it, and I can't figure out how to use it properly.
Depending on how I use it, it either loops forever, throws the error Cannot resolve caller INTERPOLATE_ASSERTION
, or returns the wrong result. Is there a proper way to use captures in lookaheads, or is this a bug?