I need to append
\n to my TRACE statement in a visual studio 2012 c++ project. That is to replace statements such as
TRACE("test an"); to
I haved tried regex
But there are two problems.
1) the regex does not match string whose last character is n, but the second-last character is not
TRACE("haha an") does not match.
2) the replacement string
\\n does not escape
\, the replaced string would contain two
Could you help me. thx.
Regex.Replace(text, "(TRACE\\(.*(?<!\\\\n))(\"\\))", "$1\\n$2");
Need to use "Zero-width negative lookbehind assertion.", see HERE
But this will add
\n even if
\n already exists. To fix this you can use regex: