Escape Regex Newline

How do I make a match \ n in a regex? I want the actual two ASCII values ​​92 and 110 to be matched (as a string).

I am using preg from PHP Thanks

+8
php regex preg-replace ascii
source share
2 answers

You can either escape the first slash: \\n

Or wrap the first slash in []: [\]n

+8
source share

if you do not want to match the real string, but a string (with two characters), such as '\n' , you just need to avoid the backslash with another \\n so that it is not recognized as linebreak.

But most programming languages ​​are slightly different when it comes to escaping, so you need to check your language documents for this, but maybe two backslashes will work.

+2
source share

All Articles