const regex = /£\d+\.\d{1,2}/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('£\\d+\\.\\d{1,2}', 'g')
const str = `<div style="float:left;"><a class="url" href="http://www.amazon.co.uk/AllThingsAccessory%C2%AE-Sports-Running-Jogging-... src="http://ecx.images-amazon.com/images/I/51bQWjrCioL._SL160_.jpg" alt="AllThingsAccessory Sports" border="0" hspace="0" vspace="0" /></a></div><span class="riRssTitle"><a href="http://www.amazon.co.uk/AllThingsAccessory%C2%AE-Sports-Running-Jogging-...® Sports Running Jogging Gym Armband Arm Band Case Cover Holder For iPhone 6 5 5S 5C 4S 4</a></span> <br /><span class="riRssContributor">AllThingsAccessory®</span> <br /><img src="http://g-ecx.images-amazon.com/images/G/02/x-locale/common/icons/uparrow... width="13" align="abstop" alt="Ranking has gone up in the past 24 hours" title="Ranking has gone up in the past 24 hours" height="11" border="0" /> <font color="green"><strong>52,006%</strong></font> Sales Rank in Sports & Outdoors: 50 (was 26,053 yesterday) <br /> <img src="http://g-ecx.images-amazon.com/images/G/02/detail/stars-4-5._V192253866_... width="64" height="12" border="0" style="margin: 0; padding: 0;"/>(51)<br /><br /><a href="http://www.amazon.co.uk/AllThingsAccessory%C2%AE-Sports-Running-Jogging-... new: </a> <strike>£7.99 - £9.99</strike> <font color="#990000"><b>£4.99</b></font> <br /><br />(Visit the <a href="http://www.amazon.co.uk/gp/movers-and-shakers/sports/ref=pd_zg_rss_ms_sg... & Shakers in Sports & Outdoors</a> list for authoritative information on this product's current rank.)`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// 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