Escape Regex Newline

吃可爱长大的小学妹 提交于 2019-12-30 08:26:10

问题


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


回答1:


You can either escape the first slash: \\n

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




回答2:


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.



来源:https://stackoverflow.com/questions/9842404/escape-regex-newline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!