I can’t figure out why this is not stopping where I thought it should.
Here is the example string.
<div class="blah"><a href="www.foo.bar">foo bar</a></div>
<div class="blah2"><span><a href="www.bar.foo">bar foo</a></span></div>
This grouping repeats itself over and over so I’m using the following.
preg_match('@<div class="blah">.*</span></div>@', $page, $matches);
It works but gets every single grouping at once instead of one at a time. Am I missing something simple here?
Thank you.
Try:
.*matches greedily, so it will encapsulate as much as it can within that.*before matching the rest of the regex..*?matches reluctantly, so it matches as little as possible before continuing to the rest of the regex.