Hi folks,
I have a string, an example below, I want to extract the number from it.
<p class="the-price">€15.00</p>
<p class="gbox"><!--<a href="#"><span>Arrange<br>
Cover</span></a>--></p>
Can anybody help with some reg exp for it?
thanks in advance.
rpkamp
2
I usually “cheat” when doing this, meaning I do something like
<p>€ 15.00</p><p class="the-price" style="display:none">15</p>
Simply because I feel that any regex is bound to fail some time (what if you don’t take thousand separators into account, etc …)
Of course when you don’t control the output of the website it becomes another story …
I would just do this:
var frag = document.createElement('div');
frag.innerHTML = theString;
var price = frag.firstChild.firstChild.nodeValue.split(';')[1];
With just regex:
var thePrice = /.+(\\d+(\\.\\d+)?).+/.exec(theString)[1]