preg_match not capturing obvious match
08:27 31 Aug 2026

I'm at an utter bottleneck because of this issue. I'm sure I'm probably making some extremely simple mistake, but I have no idea what it could be.

I have a variable $html, which contains a string of cleaned HTML taken from an external .html file. When echoed, the string renders as proper HTML. It even renders when var_dumped!

I need to look up the one div element that's just inside the body element. With the

tags and all. My goal is to echo this div in a specific section of the page.

And yet, with this piece of code:

$pattern = "//u";
preg_match($pattern, $html, $matches);

var_dump($matches);

the dumped value is just "array(0) { }".

Which is fascinating, since I know with 100% certainty that the string of HTML does, in fact, include the div. It also includes several divs inside that div. And yet absolutely nothing comes up.

What am I doing wrong?

php html regex preg-match