News for hackers. Stuff that matters.
Re:Oh Yes You Can Use Regexes to Parse HTML by pak on Friday July 08, 2011 @10:37AM (#2742578)
This is correct. As soon as I saw his lex_html function, I could see that he was using regexes to tokenize and then basically drop into different contexts while consuming the document, thereby tracking multiple levels of state throughout. That's what a full-blown parser does and it goes beyond the scope of regular languages.

By "parsing with regular expressions" most people mean applying one or two regexes to the entire document and using, for example, the group capture facility to extract information. That is and will always be a bad idea for HTML, because HTML is not a regular language.

Applying regular expressions to tokenize a string for a parsing is actually a fairly standard pattern.

Re:Oh Yes You Can Use Regexes to Parse HTML by justinhj on Friday July 08, 2011 @12:23PM (#2743065)
Exactly. Gnu's Flex lets the user define regex's for each state of the parser... http://flex.sourceforge.net/manual/Patterns.html#Patterns
Re:Oh Yes You Can Use Regexes to Parse HTML by LukeShu on Friday July 08, 2011 @01:41PM (#2743365)
Flex is used by the GNU System, but it is not GNU. It is incorrect to call it "Gnu's Flex". http://www.gnu.org/software/flex/
Re:Oh Yes You Can Use Regexes to Parse HTML by justinhj on Friday July 08, 2011 @09:31PM (#2744745)
You're quite right, thanks