Search code examples
phpregexpreg-matchpreg-match-all

Regular expression matching all characters including carriage return


What is the regular expression that matches all characters (.*) also with a carriage return?


Solution

  • Regular expression that matches all characters (.*) with also carriage return?

    It is

    (?s).*
    

    See demo

    The (?s) flag makes . match any character, even a newline.

    The flag can be set after the second delimiter, too:

    $re = "/.*/s"; 
    

    See another demo