I've been using this regular expression to pull out mustached {{Hello}} content:
/{{\s*[\w\.]+\s*}}/g
It's falling down when the mustached string contains square brackets. I've been fiddling with it for ages to no avail, could anyone suggest an adjustment that will mean it will match {{Hello[0]}} ?
I'm your Huckleberry:
\{\{(.*?)\}\}
I always hack around with these using the excellent http://www.regexr.com/
So, to explain why this works for this situation:
\{\{
– we escape (by 'escaping' with a backslash the next character doesn't get evaluated by the expression, e.g. it just looks for that character) the first character we are looking for (the curly brace). (
to make a 'group' to capture multiple tokens – so we can grab everything inside the braces..
matches any characters except line breaks.*
matches zero or more of the preceding token (in this case any token except line breaks)?
makes the previous quantifier 'lazy' in that it will match as few as possible.)
.\}\}