Please could someone explain to me why this regex does not match anything, when it should:
preg_match('@<title>([^<].)</title>@',$meta,$match);
I'm trying to match everything between the <title>
and </title>
tags, bearing in mind that there could be more than one, so the regex must be ungreedy.
You must mean ([^<]+)
or ([^<]*)
instead of ([^<].)
as the latter means to match something not <
and followed by any character
That .
will just match one character (any character). You'll want to slightly modify the preceding expression ([^<]
--"don't match an open caret"). To make it match more than one, add a *
. To make that ungreedy, add a ?
:
preg_match('@<title>([^<]*?)</title>@',$meta,$match);