I am looking for a 'Regex' to replace \\n\\
from my string. I already looked thorough this post and other regex posts here, but in my case I need to remove the value \\n\\
from a string not a new line or ( \\n
).
For example:
string eneteredString = @"abc\n\def\n\ghi\n\\";
Here \\\\
can be found multiple times too.
I have already tried Replacing Enviornment.NewLine
, as it is not a new line in my case, it also didn't work. When I try below code,
string regout = Regex.Replace(enteredString, @"\n\","");
It says parsing "\\n\\" - Illegal \\ at the end of pattern
. Can you anyone please help me with the same. Thanks in advance.
Who need regex?
string regout = @"abc\n\def\n\ghi\n\\".Replace(@"\n\", "");
And just because quotes are cool, here is the famous :
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
This is what you want. The reason is due to how regex handles the single \\
string regout = Regex.Replace(enteredString, @"\\n\\","");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.