I am trying to match {{anything}} using the regular expression
/\{\{.*\}\}/
But it will not end upon the first }}, but on the last in the document.
{{anything}} {{anotherthing}}
will return that whole chunk, instead of two matches. How can I formulate this expression to be less greedy?
I tried to do
/\{\{[^\}].*\}\}/
but it returned no results, same thing for
/\{\{.*?\}\}/
Bonus – to not get the curlies, but just the string, I tried
/\{\{(.*)\}\}/
with more failure (returned empty as well). How can I also get a subset of a match?
One time my teacher told me that she could teach me regular expressions in 15 minutes. I never got that lesson, and I’m not convinced. 🙂
You should use a non-greedy star to achieve this (adding the question mark) :
You can read more on this here
For the last part, matching only the string without the braces, take a look at “lookbehind” and “lookahead” here