Reputation: 1
I have this block of HTML and I am trying to isolate the price:
<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.)
and I am using this regex to get to the first pound sign:
(^[^£]*)
How do I apply an additional expression to limit to the 2 characters after the first decimal? Or is there another way of doing this?
Thanks in advance :)
Upvotes: 0
Views: 413
Reputation: 59232
Well, you can simply use
/£\d+\.\d{1,2}/g
The above matches £
followed by any digits (\d+)
and then matches .
and then matches digits limited to one digit and two digit using quantifieres {1,2}
.
Upvotes: 2
Reputation: 301
search for this:
£\d+\.\d{2}
It will search for the £-symbol, followed by a number (multiple digits), foloowed by a dot, follwed by two digits. This will find the first occurance in your html. When you add the global switch /g, you will find every pattern in your text
Upvotes: 0