You need a look ahead assertion. In this case a negative look ahead assertion (?!to\b|from\b):
use strict; use warnings; while (<DATA>) { print "Matched $_" if /train times (?!to\b|from\b)\w/; } __DATA__ train times to xyz train times from xyz train times including xyz train times tomorrow xyz
Prints:
Matched train times including xyz Matched train times tomorrow xyz
Update: fixed missing \b bug
In reply to Re: negate pattern match
by GrandFather
in thread negate pattern match
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |