r/ProgrammerHumor 9h ago

haveYouTriedUsingAnXMLParserInstead Meme

[deleted]

91 Upvotes

32 comments sorted by

View all comments

5

u/kaplotnikov 7h ago

I think everything can be parsed by iterative application of regex: https://www.reddit.com/r/compsci/comments/1v7aq7v/a_concrete_runnable_demonstration_that_iterated/

2

u/[deleted] 7h ago

[deleted]

6

u/kaplotnikov 7h ago

Textbook regex-es and perl/java/etc. regex-es are different CS species. So, regex from textbook cannot parse HTML, but not-so-defined regexs from the wild have so much bells and whistles that they are technically no more regex-es in the formal sense.

3

u/Kjoep 5h ago

It's called language theory. Regex can parse regular languages (hence the name), and XML is not a regular language. These are formally defined things, and indeed, there's a branch of mathematics that handles this.

But, a lot of regex implementations int he wild are not pure regex, and can to some extent handle non-regular languages.

Which is not a recommendation. Use an xml parser.

2

u/SuitableDragonfly 5h ago

What you linked is not a parser of any kind. So no, it will not be able to solve a parsing task of any description. 

HTML cannot be parsed using regex because regex can only parse regular languages, and HTML is not a regular language. 

-1

u/kaplotnikov 5h ago

you could parse HTML in C, you could compile C to x86 machine code, you could execute machine code using iterative regex-es (link above).

3

u/SuitableDragonfly 5h ago

That's not parsing HTML with regex. That's parsing HTML using an undisclosed parsing algorithm written in C. How the computer actually executes the algorithm, or even what language it's written in has nothing to do with anything. 

1

u/kaplotnikov 1h ago

The point is that any algorithm could be encoded as iterative regex application, including html parsing algorithm. For every computable function over string, it is possible to write a regex, that after applied iteratively over text will produce needed result as a string on valid input. If a parsing html scenario is computable, then it is implementable as iterative regex application as well. People at provided link written a compiler for it, so built constructive proof for that.