rovf has asked for the wisdom of the Perl Monks concerning the following question:
I thought this would be easy, but somehow I'm stuck: I'm looking for a regexp which matches names, where the left part of the name is, say FOO, and the right part of the name is *not* BAR or BAZ. I guess this is one way to do it, though I'm not sure whether $1 probably will be messed up by the parentheses in the second regexp:
Anyway, I would prefer doing it with a single regexp only. I started with:$name =~ /^FOO(.*)$/ && $1 !~ /^(BAR|BAZ)$/
but of course this is not quite right, since it would also reject FOOBARX. I wonder whether there is a simple way to solve this with Perl regexp?$name =~ /^FOO(?!(BAR|BAZ)).*$/
|
|---|