I have a string like this:
This is a {{text}} for {{testing}} PHP {{regular expression}}
I use the following pattern to get an array containing {{text}} , {{testing}} , {{regular expression}}
/\{\{.+\}\}/
But it returns an array with only 1 element:
“{{text}} for {{testing}} php {{regular expression}}”
Also tried this one:
/\{\{(?R)|.+\}\}/
But I get the same result.
What’s wrong with this pattern?
Thanks.
Try using
/\{\{.+?\}\}/, notice the ?, the original is greedy, that means it will match as many characters as it can, and if you have .+ it means it will go from the first { to the last }.The
+?,*?are the non-greedy versions of+and*.