0

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.

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by richieking
0

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

Edited by snippsat: n/a

0

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?

0

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. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.