regex: match all including new line
I was looking for a way to match all characters plus new line and using “.” is not solely the answer because:
The dot matches a single character, without caring what that character is. The only exception are newline characters. In all regex flavors discussed in this tutorial, the dot will not match a newline character by default. So by default, the dot is short for the negated character class [^\n] (UNIX regex flavors) or [^\r\n](Windows regex flavors).
So I found some answers on the references below by using the \s
So combining it all example showed below:
$str = ‘you \n are \n good’;
preg_match(‘/(.*)/s’, $str, $match);
[additions] After testing several examples I found out that S is not enough for the example below, so instead I added the U pattern modifier so it would be like preg_match(‘/div(.*)<\/div>/sU’, $str, $match);
You can also check regular expressions list here.