Reputation: 969
How to find <
tags not followed by ?
$htmlStr = " ba <div>b <? </div>n";
$regex1 = '#<#'; // finds 3 '<'
$regex2 = '#<(?!?)#'; // does not find anyhting, although should find two '<' not followed by '?'
Upvotes: 1
Views: 102
Reputation: 92854
?
is a special character in your regexp pattern and should be escaped:
$htmlStr = " ba <div>b <? </div>n";
$regex2 = '#<(?!\?)#'; // <-- will find 2 matches
Upvotes: 1