regexmultiline

How do I match any character across multiple lines in a regular expression?


For example, this regex

(.*)<FooBar>

will match:

abcde<FooBar>

But how do I get it to match across multiple lines?

abcde
fghij<FooBar>

Solution

  • It depends on the language, but there should be a modifier that you can add to the regex pattern. In PHP it is:

    /(.*)<FooBar>/s
    

    The s at the end causes the dot to match all characters including newlines.