Why does this regex, using “not” & a backref, require a lazy match?

jatirrepe

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