Don't ask to ask, just ask | |
PerlMonks |
Re: positive regex for inverted matchby BrowserUk (Patriarch) |
on Feb 26, 2004 at 08:01 UTC ( [id://331933]=note: print w/replies, xml ) | Need Help?? |
If the program that's calling the function is accepting a regex input by a user, requiring them to use '/^(?:(?!bar).)*$/s' when they want to find things that don't contain some word or phrase is not very friendly. If the input is simple text, you might get away with passing "/^(?:(?!$their_input).)*$/s", thus wrapping their input in the appropriate construct if they specified 'NOT bar' or '!bar', or some flag to indicate that they want to invert the sense of the comparison. You'd have to strip the flag from the input before calling the function. But if your going to have a flag they can use to indicate the inversion of the match, why not simply pass that flag through to the function and use it to determine the operator to use
That's the way grep -v works, which is a pretty good precedent. Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"Think for yourself!" - Abigail Timing (and a little luck) are everything!
In Section
Seekers of Perl Wisdom
|
|