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;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.

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
    Outstanding! Thanks much, especially for the detailed explanation. Worked perfectly!