Help!
If I use the construct (?(condition)yes-pattern) in a regex, and the condition is (?{1}), i.e. always true, the output is as expected:
my $str = 'bxAybz'; while ( $str =~ /(?(?{1})(b[xyz]))/g ) { say 'yes'; say $1; } --output:-- yes bx yes bz
But when I use the condition (?{pos() % 2 == 0}), I expect the same output, but I don't get it:
my $str = 'bxAybz'; while ( $str =~ /(?(?{pos() % 2 == 0})(b[xyz]))/g ) { say 'yes'; say $1; } --output:-- yes bx yes Use of uninitialized value $1 in say at 2.pl line 9. yes bz
Three matches?
Also, I notice the x modifier doesn't work with a conditional pattern:
my $str = 'bxAybz'; while ( $str =~ / (? (?{1}) (b[xyz]) ) /gx ) { say 'yes'; say $1; } --output:-- Sequence (? ...) not recognized in regex; marked by <-- HERE in m/ (? <-- HERE (?{1}) (b[xyz]) ) / at 2.pl line 12.
In reply to Re: A regex that only matches at offset that are multiples of a given N?
by 7stud
in thread A regex that only matches at offset that are multiples of a given N?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |