2 ms·
Shouldn't my $regex = qr/0(??{$regex})*1/; # (1) rather be my $regex = qr/0(??{$regex})?1/; # (2) ? Otherwise it matches many other strings (e.g. 00
by madars 17y ago
Shouldn't
my $regex = qr/0(??{$regex})*1/; # (1)
rather be
my $regex = qr/0(??{$regex})?1/; # (2)
? Otherwise it matches many other strings (e.g. 001011) in addition to 0^n 1^n; you actually want it to match zero or one times instead of zero or more. Unfortunately the explaination why (1) works is a bit faulty.
I didn't know recursive regexes before, thanks for the article.
- pkrumins 17y agoYou're right! I just fixed this serious error in the article and updated the explanation. Thanks! I was thinking about ? but wrote it down as * without realizing that * may insert several $regex$regex... thus breaking the regex.