JSFiddle - React, Tailwind, and code Playground
JavaScript
var str = '\
<a href="www.google.com" title="some title">\
<a href="www.google.com" title="some other title">\
<a href="www.google.com">\
<img href="www.google.com" title="some title">\
';
var matches = [];
//-- somewhat hacky use of .replace() in order to utilize the callback on each <a> tag
str.replace(/\<a[^\>]+\>/g, function (match) {
//-- if the <a> tag includes a title, push it onto matches
var title = match.match(/((title=".+")(?=\s*href))|(title=".+")/igm);
title && matches.push(title[0].substr(7, title[0].length - 8));
});
document.body.innerText = JSON.stringify(matches);