I have a regex that matches all the links in an html code, but I'd like to match only those links that have a certain pattern in either its text or in any of its attributes. In fact, I want to match only those links that have the pattern ${whatever_text}
.
I'll give you an example to clarify things:
var text = '<a href="/foo">foo</a> some sample text <a href="${bar}">bar</a>';
var pattern = /<a (.+?)<\/a>/igm;
var matches = text.match(pattern);
document.write(matches);
The previous regex matches the two links in the text, but I need to build a regex that matches only the last link. I've tried with the following regex /<a (.*?\$\{.+?\}.*?)<\/a>/igm
but it matches everything in between the opening tag of the first link and the closing tag of the second link.
var text = '<a href="/foo">foo</a> some sample text <a href="${bar}">bar</a>';
var pattern = /<a (.*?\$\{.+?\}.*?)<\/a>/igm;
var matches = text.match(pattern);
document.write(matches);
Thanks beforehand!