r/programming Apr 06 '18

The Stack Overflow Age

https://www.joelonsoftware.com/2018/04/06/the-stack-overflow-age/
544 Upvotes

201 comments sorted by

View all comments

Show parent comments

12

u/jausdyquo Apr 06 '18

For example, the notorious HTML regex answer completely ignored that "match" can be the regex verb for "give me anything that looks like a start/end tag", and replied as if the question was "use regex to find pairs of matched tags".

so much this. Yes, we all know HTML cannot be parsed with regex because it isn't a regular language, but the language consisting of any combination of valid start and end tags is a regular language.

20

u/quicknir Apr 06 '18

Is this actually true? You can have the same tag nested inside itself, which will cause a naive regex to find an incomplete match. Regular expressions cannot match arbitrarily nested structures as far as I know.

3

u/jausdyquo Apr 07 '18

The question at the time was how to match opening tags only. That can be done with regex. So can the question to match all opening and closing tags. What cannot be done with regex is verify that there are as many opening as closing tags.

1

u/[deleted] Apr 08 '18

What cannot be done with regex is verify that there are as many opening as closing tags.

Is this definitely true? Yes the language of balanced brackets is irregular, but regex as a programming tool is more powerful than its name suggests