Code
(preg_match_all("#\[level-(.+)-\](.+?)\[/level\]#", $string, $matches)
Problem
if I assign any value to $string with enter, my regex doesn’t work.
Example:
//This doesn't work
$string = '[level-0-]This is a
test[/level]';
//This works
$string = '[level-0-]This is a test[/level]';
What I Want
I would like my regex to work no matter what characters between (enter, etc..).
I will be glad if anyone could help me out with this one. I still didn’t dig into regex yet so I’m not that good with it 🙁
You just need the DOTALL flag
/sin your regex. This allows the dot.to match any character, including linebreaks (which it doesn’t do per default).See also the PCRE flags list http://php.net/manual/en/reference.pcre.pattern.modifiers.php