I have used http://www.regexr.com/ to try to learn about the regex sintaxis which I am applying with PHP. However, I'm sure there is a better way to write this expression:
(?:\"price|price\")+(?:[^\>])*(?:\>)+((?:[^\>](?!\/))+)+(?:[^\>])*(?:\>)*([^\<]*(?!\/\>))
I am trying to retrieve the price values for the following text:
A <span class="price-sales">$80.00</span>
B <div class="ProdMargin"><font class="items_price" >€19,75</font></div>
C <div class="price" id="text-price"> foo
<span >EUR 149 €</span>
</div>
D <div class="price" id="text-foo"> <span >149 €</span></div>
E <div id="text-price" id="foo"> <span >149 EUR</span></div>
F <div class="foo">bar</div>
Desired mathes are:
- A $80.00
- B €19,75
- C EUR 149 €
- D 149 €
- E 149 EUR
The main issue is that I have had to create 2 "matching groups": (A,B) one for for ordinary matches and (C,D,E) values that are in a second degree child.
Questions:
- 1) Am I doing anything wrong? or can it be improved?
- 2) Can I get just one outcoming "match group"?
Much appreciated!