in reply to negate pattern match
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: negate pattern match
by Anonymous Monk on Jan 31, 2006 at 14:14 UTC | |
by GrandFather (Saint) on Jan 31, 2006 at 18:39 UTC | |
by Anonymous Monk on Feb 02, 2006 at 10:56 UTC | |
|
Re^2: negate pattern match
by Anonymous Monk on Jan 31, 2006 at 10:00 UTC |