PHP Regex: How to match \r and \n without using [\r\n]?

后端 未结 7 1083
予麋鹿
予麋鹿 2020-11-27 05:58

I have tested \\v (vertical white space) for matching \\r\\n and their combinations, but I found out that \\v does not match \\r

相关标签:
7条回答
  • 2020-11-27 06:45

    If there is some strange requirement that prevents you from using a literal [\r\n] in your pattern, you can always use hexadecimal escape sequences instead:

    preg_match('#[\xD\xA]+#', $string)
    

    This is pattern is equivalent to [\r\n]+.

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