<?php
$s = "<h2>1</h2>unstructed string1<h2>2</h2>unstructed string2<div>some data</div>";
preg_match_all("`<h2>(.*)</h2>(.*)(<h2|<div)`isU", $s, $m);
var_export($m);
?>
result is
array (
0 =>
array (
0 => '<h2>1</h2>unstructed string1<h2',
),
1 =>
array (
0 => '1',
),
2 =>
array (
0 => 'unstructed string1',
),
3 =>
array (
0 => '<h2',
),
)
My aim is to find data between h2 and data after h2 tag. Only fist h2 related data found.
Data after h2 tag sometime ends by div sometime by h2 tags.
As I understand in second case internal prce positon move inside h2 tag and therefore php do not find second h2 tag.