good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Match something that does not matchby jo37 (Deacon) |
on Feb 15, 2020 at 17:42 UTC ( [id://11112994]=perlquestion: print w/replies, xml ) | Need Help?? |
jo37 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
every now and then I stumble upon the question of how to match something that doesn't match something else. I.e. some expression in the sense of [^...]* for a general given regex $match. The best I got so far is:
The first branch matches a substring up to the given regex $match if there is a match and the second branch matches the whole string if there is no match. Both fail in the opposite case. (The second branch by missing the last character.) Does anybody know something simpler? Or do you see any issues with the given regex? Here is a small example:
I might put this into an extension module for Regexp::Common, but I'm not sure if this makes sense at all. And what would a proper naming be? Maybe something like:
Your opinions? -jo
Back to
Seekers of Perl Wisdom
|
|