如何在php xpath查询($xpath->查询)中使用regex ?

时间:2023-01-08 15:45:12

I would like to search links that contain "click" or "click here" text as anchor text.

我想搜索包含“单击”或“单击这里”文本的链接作为锚文本。

If it matches then it should return href values.

如果匹配,则返回href值。

Can someone tell me how to use regex here?

有人能告诉我如何使用regex吗?

1 个解决方案

#1


3  

You can't use regex with PHP's DOMXPath. matches() was added in XPath 2.0, but DOMXPath only supports XPath 1.0.

您不能使用PHP的DOMXPath来使用regex。在XPath 2.0中添加了matches(),但是DOMXPath只支持XPath 1.0。

You can try using contains():

您可以尝试使用contains():

//a[contains(text(), "click here")]

#1


3  

You can't use regex with PHP's DOMXPath. matches() was added in XPath 2.0, but DOMXPath only supports XPath 1.0.

您不能使用PHP的DOMXPath来使用regex。在XPath 2.0中添加了matches(),但是DOMXPath只支持XPath 1.0。

You can try using contains():

您可以尝试使用contains():

//a[contains(text(), "click here")]