Remove namespaces from Xpath expression

If you ever need to remove namespaces from an XPath string, regex is a way to go. [\w]+:(?!:) expression to be precise. So if, for example your xpath is

Dim sXpath as String = "/ns1:ElementOne/ElementTwo/ns2:ElementThree"

this code

Regex.Replace(sXpath, "[\w]+:(?!:)", "")

will convert it into


Thanks Bogdan Emil Mariesan @ Stack Overflow for the solution

Leave a Reply

Your email address will not be published. Required fields are marked *