r/ProgrammerHumor • • Sep 08 '17

Parsing HTML Using Regular Expressions

Post image
11k Upvotes

377 comments sorted by

View all comments

Show parent comment

1

u/Feynt Sep 09 '17

Then yes, doing a single regex to match all of an HTML file is pointless. The very nature of the match variable limit makes it impossible to do in one go unless it's a very small file. If it's an iterative process though, you most certainly could match the tags properly and grab their insides for recursive processing in another language.

1

u/link23 Sep 09 '17

That's not the point - we're talking about theory, not practice. Even if you had infinite time and had a machine that could perform any regex match, no matter how large, it's still not possible. A regular expression cannot hold enough information to express the constraints of HTML. (The real kicker is matching nested tags - it's not possible to enforce that every tag is closed properly if it should be.)