tvance tvance - 9 months ago 53
HTML Question

Javascript RegExp Selector for HTML Template Strings

I need some help with my JavaScript regex. I need a way to select the following:


from the following html:


There could be multiple
with different values in them and the 'user' part of the string is not always going to be user. It could be anything.

Ideally I would like them back as an array, although at the moment I'll settle for anything.


I am not regex expert but I hope it will work.

var str = "your html"
var matches = str.match(/\${[a-zA-Z0-9.]+}/g);

For your given input html, output will be

["${}", "${user.age}"]