0

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 :)

2 Answers2

2

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}.

DEMO

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
0

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

boulder_02
  • 301
  • 1
  • 6
  • Actually... I've realised what I need is the exact opposite of this, because I'm having to use Regex Find Replace. What would Regex for that be? – user2653665 Oct 13 '14 at 13:11
  • Which part do you have to replace? The regular expression finds a defined character sequence and you can replaces that with sth else. So you have to specify, which part of the matched string you want to replace by sth else. Ie replace £ with 'Pound' or sth like that. – boulder_02 Oct 14 '14 at 07:44
  • It's fine. I was able to do it this way in the end. Thanks! – user2653665 Oct 14 '14 at 12:28