Escape Regex Newline

后端 未结 2 513
轮回少年
轮回少年 2021-01-12 06:29

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

相关标签:
2条回答
  • 2021-01-12 06:57

    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.

    0 讨论(0)
  • 2021-01-12 07:05

    You can either escape the first slash: \\n

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

    0 讨论(0)
提交回复
热议问题