Regex Readability

Piers describes a foul abuse of programming. I’m totally with him on this one. People should just learn to use regexes—they’re an enormously powerful tool for pulling apart strings. And they’re not difficult. Unless of course, you’re of the “Java is the one true language and I must know nothing else” school of programming. Don’t laugh, there are people like that.

But the second crime, which Piers fails to point out is parsing XML with a regex. There are so many ways in which this will blow up in your face. Really. What about character encodings? Attribute order? Entities? Even unexpected tag order would blow up most XML regexes I’ve seen. Don’t do it, folks, you’re just setting yourself up for a fall.

Update: Dave and Piers both correctly point out in the comments that I misread the original article. Piers does in fact state that parsing XML is “one of the canonical no nos”. Mea Culpa. I still agree with everything he says.