I’m trying to run regular expression on the following string with PHP using preg_match_all function
“{{content 1}}{{content 2}}”
The result I’m looking for is array with 2 matches inside {{ and }}
Here is the expression '/\{\{(.+)\}\}/'
I’m suspecting that my expression is too greedy but how to make it less greedy?
You can use the ungreedy modifier
?, like so:New regex will output:
EDIT:
Just remembered another way to do this. You can just add a
U(capital u) in the end of your regex string and result will be the same, like so:Also, here is a useful list of regex modifiers.