Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath matches() using regular expressions in C#

Tags:

c#

regex

xpath

Update: I wrote up what I did, with source code and things to watch for, at - Adding XPath 2.0 functionality and variables to .NET XPath (my blog).

Is there a way to pass a regular expression to matches() for an XPath statement in .NET?

Example: do an xpath of

"/windward-studios/Employees/Employee[matches(string(LastName), '.*A?B[12]C.*')]"
like image 872
David Thielen Avatar asked Dec 16 '25 20:12

David Thielen


1 Answers

XPath 2.0 supports the matches function. However, .Net implements XPath 1.0.

You would need to add a custom function to implement match. See http://msdn.microsoft.com/en-us/library/ms950806.aspx

It looks like the Mvp.Xml Project: EXSLT.NET module implements most of XPath 2.0; including matches. See http://mvp-xml.sourceforge.net/exslt/

like image 198
Richard Schneider Avatar answered Dec 19 '25 10:12

Richard Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!