Add a question mark after the star.
/[%][{]\s*((.|\n|\r)*?)\s*[}][%]/gm
Anton Hansson
2010-02-15 01:42:33
Add a question mark after the star.
/[%][{]\s*((.|\n|\r)*?)\s*[}][%]/gm
Firstly, to make a wildcard match non-greedy, just append it with ?
(so *?
instead of *
and +?
instead of +
).
Secondly, your pattern can be simplified in a number of ways.
/%\{\s*([\s\S]*?)\s*\}%/gm
There's no need to put a single character in square brackets.
Lastly the expression in the middle you want to capture, you'll note I put [\s\S]
. That comes from Matching newlines in JavaScript as a replacement for the DOTALL
behaviour.