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

后端 未结 7 1129
予麋鹿
予麋鹿 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:30

    This regex also matches newline \n and carriage return \r characters.

    (?![ \t\f])\s
    

    DEMO

    To match one or more newline or carriage return characters, you could use the below regex.

    (?:(?![ \t\f])\s)+
    

    DEMO

提交回复
热议问题