Your substitution will correctly leave the \n in \\n alone, but what about \\\n? The backslash preceeding \n is itself preceeded by a backslash, so the \n should be converted in that case. \\\\n, on the other hand, shouldn't get the \n converted.
What is needed is something to match pairs of backslashes before the \n, like this:
s/((?<!\\)(?:\\\\)*)\\n/$1\n/g;
| [reply] [d/l] |
s#(?<!\\)((?:\\\\)*)\\n# '\\'x(length($1)/2) . "\n" #ge;
# or
s#(?<!\\)(\\*)\1\\n#$1\n#g;
I find that having to escape your backslashes only when
they preceed a (desired) newline to be confusing so I'd
go with japhy's excellent sugestion or perhaps:
s#\\([\\n])# $1 eq "n" ? "\n" : $1 #ge
-
tye
(but my friends call me "Tye") | [reply] [d/l] [select] |