in reply to Replace only unescaped metachars
So, applying the idea I linked to above, we get this.
This outputs$_ = "t?e\\\\xt\\\\* with escapes\\*\n"; s/\\\\/\\s/g, s/(?<!\\)\?/#/g, s/(?<!\\)\*/?/g, s/\\(\W)/$1/g, s/\\s/\ +\/g; print;
t#e\xt\? with escapes*
Update: without lookarounds (this is what you'd do if all you had was sed):
$_ = "t?e\\\\xt\\\\* with escapes\\*\n"; s/\\\\/\\s/g, s/\\\?/\\S/g, s/\\\*/\\T/g, s/\?/#/g, s/\*/?/g, s/\\(\W) +/$1/g, s/\\S/?/g, s/\\T/\*/g, s/\\s/\\/g; print;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replace only unescaped metachars
by Anonymous Monk on Feb 23, 2007 at 11:01 UTC |