Asone Tuhid
Asone Tuhid

Reputation: 549

Ruby strange behavior with recursive regex

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.

Upvotes: 1

Views: 94

Answers (0)

Related Questions