Live data from Hacker News

Parsing HTML with Regex

stackoverflow.com

31–34 of 34 posts

Re: Parsing HTML with Regex

#31

A programmer has a problem which requires parsing. He decides to use regex. Now he has two problems.

A HN user reposts a SO post from ages ago.

Another HN user decides to repost a relevant joke from ages ago.

Now HN is going down the drain.

Re: Parsing HTML with Regex

#32

I reckon that technically regex is a tool that can be used to parse HTML. It's just that you could only use it in a very trivial way that would be better suited to other tools.

No. Technically , you cannot parse HTML with regular expressions. You can find certain strings in HTML which is a different thing.

At the very least, you can use regex to match individual characters as you scan the HTML for parsing. It's an inefficient and stupid way to do it, but it is still something you can do. And in that case, regex is technically a tool that you are using to parse HTML, even though 99.9% of the work is being done by non-regex code.

Re: Parsing HTML with Regex

#33
post #2

I had one class where we had to build a multi threaded search engine in java and parsing HTML with regex was a requirement. Regex was the downfall of about 50% of the class and the majority of the students who did well still had slight issues with their HTML parsing. Moral of the story is that regex is a poor solution for HTML. Not to mention, hours debugging regex is one of the least meaningful or rewarding experien…

> the majority of the students who did well still had slight issues with their HTML parsing. I'd like to hire the minority students, since it seems that they quite literally accomplished the impossible!

> the majority of the students who did well still had slight issues with their HTML parsing.

There were a few students who actually passed all of our professor's test cases (at least that's what they claim).

Re: Parsing HTML with Regex

#34

Earlier quoted context omitted.

I would imagine that valid HTML could be parsed as XML, e.g. with the Python ElementTree XML API

That would be true for XHTML but not for HTML as tags like paragraph do not always require a end tag, which would break XML parsing.

I was under the impression that HTML4 introduced XML requirements, thus requiring the

tag.
Post reply on HN