如何查找未跟<
?
代码
$htmlStr = " ba <div>b <? </div>n";
$regex1 = '#<#'; // finds 3 '<'
$regex2 = '#<(?!?)#'; // does not find anyhting, although should find two '<' not followed by '?'
答案 0 :(得分:1)
?
是你的正则表达式模式中的一个特殊字符,应该被转义:
$htmlStr = " ba <div>b <? </div>n";
$regex2 = '#<(?!\?)#'; // <-- will find 2 matches