in reply to Re^2: negate pattern match
in thread negate pattern match
A negative look ahead assertion at the start of the line (not a look back) is what you want:
use strict; use warnings; while (<DATA>) { print "Matched: $_" if /^(?!help).*?train times (?!to\b|from\b)\w/; } __DATA__ help train times from xyz load train times including xyz help train times including xyz book train times at 1234
Prints:
Matched: load train times including xyz Matched: book train times at 1234
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: negate pattern match
by Anonymous Monk on Feb 02, 2006 at 10:56 UTC |