Ruby strange behavior with recursive regex

90 views Asked by At

I recently stumbled into this trying to use a recursive regex:

'--01-0-01'.scan /0|1|-(\g<0>)(\g<0>)/
#=> [['0', '-0-01']]

where it seems that the first recursive pattern matched deeper than expected wile the second one performed normally. This is confirmed by regex101 which gives the correct groups ('-01' and '-0-01'). Is this a strange feature of ruby or is it a buggy implementation?

For the record, this happened while trying to solve this code golf question.

0

There are 0 answers