Hi, Dermot <paik...@googlemail.com> suggested: > 2009/11/17 mangled...@yahoo.com <mangled...@yahoo.com>:
> > 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: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/