Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape Regex Newline

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

I'm using preg from PHP Thanks

like image 742
jtnire Avatar asked Mar 23 '12 15:03

jtnire


2 Answers

You can either escape the first slash: \\n

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

like image 136
Lee Netherton Avatar answered Sep 29 '22 11:09

Lee Netherton


if you don't want to match a real linebreak but a string (with two characters) like '\n' then you just have to escape the backslash with another one \\n so that it will not be recognized as linebreak.

But most programming languages are a bit different when it comes to escaping, so you have to check your language docs for that, but two backslashes will probably work.

like image 20
luukes Avatar answered Sep 29 '22 13:09

luukes