in reply to Regex for replacing a character "not next to" another character
Try this:
$s = "\tfred\tx\t\"abc\tdef\"\ty\tz\t";; print "'$s'";; ' fred x "abc def" y z ' $s =~ s[(?<!^)(?<!")\t(?!"|$)][***]g;; print "'$s'";; ' fred***x "abc***def" y***z '
It didn't replace the tab at the beginning of the string, the one preceding the first double quote or following the second, nor the one at the end.
Expanded the regex is:
s[ (?<!^) # not preceded by the start of string (?<!") # nor by a double quote \t # replace tabs (?!"|$) # that are also not followed by a double quote or the end +of string ][***]gx;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex for replacing a character "not next to" another character
by flightdm (Acolyte) on Nov 04, 2016 at 01:58 UTC |