in reply to Find and Replace with special characters
And maybe it's just a typo in your post, but you seem to be using the =~ operator twice, which seems wrong - since you're modifying $_, you don't need it at all.
Yet another point: since you are only changing one character (# to *), you should use a "look-ahead assertion" for the other characters in the pattern.
Finally, to top it off, you put a backslash escape in front of the forward-slash character that was supposed to be the middle delimiter for the "s///' operator, so perl only sees two of the three forward-slashes as delimiters.
Try it like this:
(Update: Admittedly, using the look-ahead assertion in this case feels a bit uncomfortable, because you might get it confused with the look-behind syntax:foreach ( @lines ) { s/#(?=<-\(0N<-\(s3T)/*/g; push(@newlines,$_); }
/(?<=preceding_part)target_part/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find and Replace with special characters
by wrog (Friar) on May 07, 2015 at 08:59 UTC |