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

andyuk picture andyuk · Oct 1, 2008 · Viewed 644.3k times · Source

For example, this regex

(.*)<FooBar>

will match:

abcde<FooBar>

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

abcde
fghij<FooBar>

Answer

levik picture levik · Oct 1, 2008

Try this:

((.|\n)*)<FooBar>

It basically says "any character or a newline" repeated zero or more times.