3 ms·
Oh dear. I like this article, but using XML parsing as the example for sed made me cringe hard. Please never, ever attempt to work with XML using regular expres
by gmaslov 15y ago
Oh dear. I like this article, but using XML parsing as the example for sed made me cringe hard. Please never, ever attempt to work with XML using regular expressions!
- tjpick 15y agoI agree. However, many regular expression implementations are not regular and have enough power to parse nested structures.
- bwarp 15y agoThe "can't parse XML using regular expressions" argument is possibly flawed as it's a false dichotomy. XML is a superset of text therefore it is parseable with regular expressions, but in the context and constraint of text, not as structured XML. I.e. you can parse the textual content but not the structure with regular expressions. It's possibly a hack but ignoring a level of abstraction for the sake of simplicity works in a lot of cases absolutely fine. Let's also add the constraint that an XML parser can't mathematically parse broken XML whereas a regular expression can extract data from XML. That end of the problem is far more interesting. GEB made me appreciate this fact after some rather late nights and considerable amounts of alcohol.
- mattmight 15y agoTrue. To be fair, I noted this limitation in the example, and said that if the nesting structure is important, you should use a tool that can handle context-free languages. My more general warning was that if you find yourself exploiting the Turing-completeness of sed, you're using the wrong tool.