in reply to string substitution
Assuming "on either side" to mean "on both sides" (see my post above), try this awfully ugly code:
use strict; use warnings; my $ariths = quotemeta '()+</*><-'; while ( <DATA> ) { s/(?:(?:(?<=[$ariths])BAD)|^BAD)(?=[$ariths])/HELL/g; print; } __DATA__ +BAD # No BAD/ # Yes BAD) # Yes (BAD<) # Yes BAD # No BADGER # No BADGER+ # No +SINBAD+ # No BAD (BAD+ # No then Yes
Improvements welcome!
dave
Update: davido's corrected regex above already represents a significant improvement!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: string substitution
by Anonymous Monk on Oct 09, 2003 at 17:07 UTC | |
by davido (Cardinal) on Oct 09, 2003 at 17:22 UTC | |
by Anonymous Monk on Oct 09, 2003 at 19:16 UTC |