In javascript, I’ve got a block of HTML like this:
<h2>{title}</h2> <p><a href='{url}'>{content}</a></p>
And I’m trying use regex ‘match’ to spit out an array of all the {item}’s. So my output should look like:
['title', 'url', 'content']
I’ve gotten as far as:
var pattern = new RegExp('\{[a-zA-Z]+\}+'); var match = pattern.exec('{Sample} bob {text}');
But it’s only returning the first tag.
This is just beyond my regex skills. Can anyone help?
Cheers!
You need to create a pattern with the global flag:
or:
Then you can call the match() method on your string to get a list of matches: