Reliably Parsing Html Elements Using Regex
Possible Duplicate: Best methods to parse HTML with PHP I'm trying to parse a webpage using RegEx, and I'm having some trouble making it work in a reliable manner. Say I wanted
Solution 1:
Regular expressions describe so called regular languages - or Type 3 in the Chomsky hierarchy. On the other hand HTML is a context free language which is Type 2 in the Chomsky hierarchy. So: There is no way to reliably parse HTML with regular expressions in general. Use a HTML parser instead. For PHP you can find some suggestions in this question: How do you parse and process HTML/XML in PHP?
Solution 2:
You will need a Lexical analyser and grammar checker to parse html correctly. RegEx main focus was for searching strings for patterns.
Post a Comment for "Reliably Parsing Html Elements Using Regex"