const regex = new RegExp('<a.*\\shref=[\\"\\\\'](?:(?:\\w+)://)*((?:[\\w-]+\\.)+(?:[\\w-]+))(?::\\d+)?(?:/|$)?(?:[^\\s]+)?[\\"\\\\'].*>', '')
const str = `<a href="http://www.pochta.ru">Почта</a>
<a href="http://top100.rambler.ru/top100/All/rate21.0.shtml.ru"><img src="http://pics.rbc.ru/img/ver99/counter_rambler.gif" alt="Rambler's Top100 Service" width=88 height=31 border=0></a>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions