作者:中华oc博弈网络志 | 来源:互联网 | 2023-06-03 08:37
Ihavethisanchorlocatingregexworkingprettywell:我有这个锚定位正则表达式工作得很好:$p%<a.*\s+name(.
I have this anchor locating regex working pretty well:
我有这个锚定位正则表达式工作得很好:
$p = '%(?:.*)%im';
It matches followed by zero or more of anything followed by a space and name="
它匹配
It is grabbing the names even if a class or an id precedes the name in the anchor.
即使一个类或一个id在锚点中的名称前面,它也会抓取名称。
What I would like to add is the ability to match on name='
with a single quote (') as well since sooner or later someone will have done this.
我想要添加的是能够匹配name ='和单引号('),因为迟早有人会这样做。
Obviously I could just add a second regex written for this but it seems inelegant.
显然我可以为此添加第二个正则表达式,但它看起来不够优雅。
Anyone know how to add the single quote and just use one regex? Any other improvements or recommendations would be very welcome. I can use all the regex help I can get!
任何人都知道如何添加单引号并只使用一个正则表达式?任何其他改进或建议都将非常受欢迎。我可以使用我能得到的所有正则表达式帮助!
Thanks very much for reading,
非常感谢阅读,
function findAnchors($html) {
$names = array();
$p = '%(?:.*)%im';
$t = preg_match_all($p, $html, $matches, PREG_SET_ORDER);
if ($matches) {
foreach ($matches as $m) {
$names[] = $m[1];
}
return $names;
}
}
5 个解决方案