0

我可以匹配sometext并且othertext

<br>
sometext
<br>
othertext

使用 xpath 选择器'//br/following-sibling::text()'

<br>但是如果元素后只有空格

<br>

<br>
othertext

只有第二场比赛发生。是否也可以匹配空格?

我试过了

//br/following-sibling::matches(., "\s+")

尝试匹配空白但没有成功。

4

1 回答 1

0

'matches' 是匹配正则表达式,而不是匹配节点。它不能与轴说明符一起使用。您可以将其用作条件,例如:

//br/following-sibling::text()[matches(., "\s+")]

或者没有正则表达式(根据实现可能会更快),检查它是否全是空格而不是空字符串:

//br/following-sibling::text()[(normalize-space(.) = "") and (. != "")]
于 2012-11-20T22:14:21.427 回答