[Prepended - This is a slowish way to solve the problem. There's an eval block involved in the (?{$re}) bit which may not fit with your needs. Normally you'd just have not() in your code somewhere and use a normal regex.]
Here's a thought - use the conditional expression followed by true/false assertions. You may want to read up on it in perlre.
my $digit = qr/^\d+$/; my $not_digit = reverse_regex_assertion( $digit ); print 0+(1234 =~ $digit), 0+(1234 =~ $not_digit); sub reverse_regex_assertion { my $re = shift; return qr/(?(?{$re})(?!)|(?=))/; } # That expression broken into pieces #qr/(? # Conditional (?(expr) (true) | (false) ) # (?{$re}) # Test $re expression # (?!) # Assert false # | # OR # (?=) # Assert true # )/x
In reply to Re: reversing a compiled regex?
by diotalevi
in thread reversing a compiled regex?
by dash2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |