in reply to Programmatically forcing a regexp to fail
that you could force a failure of the regexp
It's probably the 'empty negative lookahead' (?!) :
... my @nums = 1 .. 30; my $reg = qr{^(\d+)$ (??{ $1 % 3 ? '(?!)' : '' })}x; print join ',', grep /$reg/, @nums; ...
This is documented eg. in Jeff Pinyan's work (also here on perlmonks).
Correction 1: Added bounds "^ $" to \d+ to prevent backtracking in the above example.
Correction 2: backtracking can be prevented by the atomic group (?>...):
... my $reg = qr{ ^((?>\d+)) (??{ !!($1 % 3) and '(?!)' }) }x; ...
Regards
mwa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Programmatically forcing a regexp to fail
by suaveant (Parson) on Nov 05, 2007 at 15:50 UTC |