When using the not ^
operator in combination with a back reference, why do I need to use a lazy match? It seems like the not
should break the match.
For example:
<?php
preg_match('/(t)[^\1]*\1/', 'is this test ok', $matches);
echo $matches[0];
?>
Will output this test
, instead of this t
, in spite of the fact that the middle t
does not match [^\1]
. I need to use /(t)[^\1]*?\1/
to match this t
.
Furthermore
preg_match('/t[^t]*t/', 'is this test ok', $matches);
What is going on, and what am I misunderstanding?