logoalt Hacker News

danlittyesterday at 3:10 PM7 repliesview on HN

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.


Replies

layer8yesterday at 4:29 PM

Some commenters are missing that this is a reference to https://stackoverflow.com/a/1732454.

show 2 replies
rokkamokkayesterday at 3:21 PM

You can parse a subset of it though, like if you're in control of the html yourself and avoid certain structures

zarzavatyesterday at 3:32 PM

Parsing HTML with a regex is never a good option, but it's sometimes the only option.

show 1 reply
tyhoyesterday at 4:24 PM

You can absolutely parse HTML with regex, so long as the document is finite in length. Every finite language is regular, hence can be parsed with regex's.

show 4 replies
matheusmoreirayesterday at 3:40 PM

Tony the pony, he comes.

timedudeyesterday at 4:19 PM

What do you mean you can't. I do it all the time

show 1 reply
prmoustacheyesterday at 4:34 PM

I do not count substitution as "parsing"