in reply to complex pattern matching
Here is a soultion using a /e for the substitution. Lookahead/behind assertions will not work well here so we treat 'input' as the special case of \binput\b that it is. If found we effectively leave it alone by substituting it back in - if not then we sub in OUTPUT.. The result is as desired.
$_= "input and 'input' and 'tinput' and ' input' and 'input ' and inpu +t"; s/('input'|\binput\b)/($1 eq "'input'") ? $1 : "OUTPUT"/eg; print "Got\n$_\n"; print "Want OUTPUT and 'input' and 'tinput' and ' OUTPUT' and 'OUTPUT ' and OUTPUT +";
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: complex pattern matching
by christopherbarsuk (Acolyte) on Aug 19, 2001 at 01:53 UTC |