I have this template (mustache alike):
{{varone}}
{{vartwo}}
{{#varthree}}
{{subvarone}}
{{subvartwo}}
{{/varthree}}
{{#varfour}}
{{subvarthree}}
{{subvarfour}}
{{/varfour}}
{{^varfive}}
some message
{{/varfive}}
{{age}}
{{var_a}} {{#var_b}} {{var_c}} {{/var_b}}
and I want to get varone, vartwo, varthree, varfour, varfive and varsix, but not subvars inside blocks. I have a regexp to get subgroups but it is not working well, and I tried to get every expression that does not have dash, but it algo gets subvars...
UPDATE: also it should work in single line, so it should get var_a, var_b but not var_c...
javascript: //template has the template descibed above. console.log("TEMPLATE >> ",template);
matches = template.match(/{{\s*\#\w+\s*}}[^#]*{{\s*\/\w+\s*}}/g) || [];
console.log("MATCHES groups >> ", matches);
matches = template.match(/{{\s*[\w\.\^]+\s*}}/g) || [];
console.log("MATCHES all >> ", matches);
please note that in javascript we need a trick to make dot matches also breaklines, by having [\s\S], in this case I decided to include everything but the dash to collect subexpressions. This is the console result:
MATCHES groups >> [ '{{#varthree}}\n {{subvarone}}\n {{subvartwo}}\n{{/varthree}}',
'{{#varfour}}\n {{subvarthree}}\n {{subvarfour}}\n{{/varfour}}\n\n{{^varfive}}\n some message\n{{/varfive}}' ]
MATCHES all >> [ '{{varone}}',
'{{vartwo}}',
'{{subvarone}}',
'{{subvartwo}}',
'{{subvarthree}}',
'{{subvarfour}}',
'{{^varfive}}',
'{{age}}' ]