I am using php preg_match and I have the original expression as:
|(label\">Carried Price </span> £)((.)*?)( </div)|
But I want to be able to able to be able to use the same basic expression but be able to search for Carried Price or Web Exclusive. I tried something like:
|(label\">[Carried Price|Web Exclusive] </span> £)((.)*?)( </div)|
But no luck, any ideas? I also have to keep this structure of the regex as 3 groupings.
Additional the code I am using to test with example text
$page = ' <div class="web-exclusive-price"> <span class="label">Web Exclusive
</span> £399.00 </div>
<div class="web-only-label"> <span class="label">Offer not available in-store </span> </div>
<div class="deliveryShortcut"> <span class="label"><a href="#deliverySection" onclick="navigateOpenSection(\'delivery\');">Standard Delivery</a></span> Free </div>
';
$r = '|(label\">(?:Carried Price|Web Exclusive) </span> £)((.)*?)( </div)|';
preg_match($r, $page, $matches);
You need round braces for this. Square braces
[]are used to specify set of characters. Here is fixed regexp:Symbol
(?:...)means non-capturing group. Here is more information about groups http://www.regular-expressions.info/named.htmlUpdate 1:
Also regexp is not the best way to parse html. Look at allternavite way using SimpleXML.
Update 2 (thanks to Tim Pietzcker):
If you’re using
|as regexp delimeter then you can’t use it inside regexp. I’ve replaces it with'symbol.\s+is used to match any number of spaces. Now your test code is working. See example above.