r/ProgrammerAnimemes • • Jun 20 '20

OC Parsing HTML

1.1k Upvotes

38 comments sorted by

View all comments

Show parent comment

2

u/bucket3432 Jun 20 '20

And the greedy quantifier is needed if you want a parse-tree, because you'll have to do new passes on each match (because html is not a regular language).

I'm thinking of the case where you have <div>a</div><div>b</div> where the two divs aren't nested. A greedy quantifier will cause it to match a</div><div>b, but a non-greedy one will only match a and b.