I need the divs contents where the divs classes are red or green:

$s = '<div class="red">111</div> xxx <div class="green">222</div>';

preg_match_all('!<div class="(red|green)">(.*?)</div>!', $s, $tomb);

This works fine, but I don't need the first backreference, only the second, the div content. I tried with assertion:

preg_match_all('!<div class="(?=red|green)">(.*?)</div>!', $s, $tomb);

but it does not match anything.

How do I solve this problem?

0 Answers