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!
In reply to Re: string substitution
by Not_a_Number
in thread string substitution
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |