2011-09-03 51 views
0

我有这样的:通配符XPath中的属性

//th[@style='border-bottom-color: #ce9c00; text-align: left; line-height: 25px; 

我想让它选择任何颜色,像这样的正则表达式;

//th[@style='border-bottom-color: #......; text-align: left; line-height: 25px; 

我该怎么做?我正在使用C#和Html Agility Pack。

回答

1

用火柴()XPath函数,并给它一个正则表达式是这样的。

//th[matches(@salary,'^border-bottom-color: #[0-9a-fA-F]{6}; text-align: left; line-height: 25px$')] 

注:我已经给[0-9A-FA-F],因为颜色采用十六进制十进制值,你可以简单地使用(点)的地方,如果那个。

参考:http://www.w3schools.com/xpath/xpath_functions.asp

0

您可以使用XPath 1.0字符串函数substringcontains等,例如:

//th[starts-with(@style, 'border-bottom-color: #') 
    and contains(@style, '; text-align: left; line-height: 25px;')]