Hi,
Dermot <[email protected]> suggested:
> 2009/11/17 [email protected] <[email protected]>:
> > 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 :
> 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
One could also use a zero-with negative look-ahead assertion:
#!/usr/bin/perl -w
use strict;
while( my $line = <DATA> ){
if( $line =~ m/^(?!Nomatch)/ ){
print "match: $line";
}
}
__DATA__
Line1 xxxx
Line2 yyyy
Nomatch zzzz
Line3 aaaa
Line 4 bbbb
Cheers,
Thomas
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/