Regex to match any character including new lines

后端 未结 4 1844
深忆病人
深忆病人 2020-11-28 04:39

Is there a regex to match \"all characters including newlines\"?

For example, in the regex below, there is no output from $2 because (.+?)

4条回答
  •  星月不相逢
    2020-11-28 05:01

    If you don't want add the /s regex modifier (perhaps you still want . to retain its original meaning elsewhere in the regex), you may also use a character class. One possibility:

    [\S\s]
    

    a character which is not a space or is a space. In other words, any character.

    You can also change modifiers locally in a small part of the regex, like so:

    (?s:.)
    

提交回复
热议问题