Reputation: 17013
How can I create an XPath expression that works like a regex would, so that it matches instances of next
? Here's an example of what I want using regex syntax:
string = 'blah_blah next '
xpath="//a[contains(text(),'.*?next.*')]");
I'm new to XPath, and searching through tutorials didn't help me.
Upvotes: 9
Views: 16932
Reputation:
In XPath 1.0, this expression does what you want:
//a[contains(.,'next')]
From http://www.w3.org/TR/xpath/#section-String-Functions
Function: boolean contains(string, string)
The contains function returns true if the first argument string contains the second argument string, and otherwise returns false.
For more complex matching ussing RegExp you need a XPath 2.0 processor having this built-in functions: match()
, replace()
, tokenize()
, etc.
Upvotes: 14