I have been told by a number of people to use xpath instead of regex for some of my regex searches. What advantages does xpath provide over regex? I can't find a webpage that says that. Been through over 10 pages of search so far.

Recommended Answers

All 4 Replies

It is my understanding the xpath is more for XML document searches.

I have been told by a number of people to use xpath instead of regex for some of my regex searches.

What are you searching?

Some notes about XML/webpages here is regex not the right tool.
If you are parsing(searching) XML/html you should use beautifulsoup / lxml(has XPath built in) that is designed exactly for this purpose.

Why is regex bad for xml/html read this very good answer.
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

Okay well I will be searching HTML documents and php generated pages that outputs either straight text or mimics XML. I have xml parsing down with lxml. So I should switch to all lxml and xpath?

Like snippsat said. If you need to parse html/php page you will need beautifulsoup or the hard way using regex.
The choice is yours. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.