PHP Regex Any Character

后端 未结 5 648
醉梦人生
醉梦人生 2020-12-10 01:10

The . character in a php regex accepts all characters, except a newline. What can I use to accept ALL characters, including newlines?

5条回答
  •  青春惊慌失措
    2020-12-10 01:28

    An important thing is missing here. [\s\S] matches one character, whereas a newline can be a character sequence. (Windows uses two characters: \r\n.) Neither . (with DOT_ALL modifier) nor [\s\S] will match the newline sequence. Best way to match any character or any newline is (.|\R), "everything except a newline or a newline". \R matches \n, \r and \r\n.

提交回复
热议问题