2009/11/17 [email protected] <[email protected]>:
> Hi,
Hello,
> Can anyone tell me hoq to write a regular expression which matches
> anything _except_ a litteral string ?
>
> For instance, I want to match any line which does not begin with
> Nomatch. So in the following :
>
> Line1 xxxx
> Line2 yyyy
> Nomatch zzzz
> Line3 aaaa
> Line 4 bbbb
>
> I would match every line except the one containing "Nomatch zzzz"
You would negate the pattern. Something like this:
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA>) {
print if ! /^Nomatch/;
}
__DATA__
Line1 xxxx
Line2 yyyy
Nomatch zzzz
Line3 aaaa
Line 4 bbbb
~
Output:
Line1 xxxx
Line2 yyyy
Line3 aaaa
Line 4 bbbb
see
perldoc perlop #Logical-Not
and
perldoc perlsyn
and of course
perldoc perlrequick
HTH,
Dp.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/