Although I don't understand the original question (mabye due to bad formatting?) I can tell that the /m modifier on your regex doesn't do anything - it merely affects ^ and $ to match line start/ending (instead of string start/ending).
You probably meant the /s modifier instead, which makes . also match a newline.