3 ms·
He specifically said "since it was all inside a single tag". Without knowing what the payload of the tag is, its hard to say if regex was appropriate or not.
by vonmoltke 13y ago
He specifically said "since it was all inside a single tag". Without knowing what the payload of the tag is, its hard to say if regex was appropriate or not.
- kelseyfrancis 13y ago> its hard to say if regex was appropriate or not I'd say it's never appropriate to parse XML with a regex. Even if you're just looking for something "inside a single tag", there are just too many gotchas like entities, CDATA sections, etc. Why bother with (or forget) any of that when there are well-tested XML libraries for probably every language, and many languages have it in their standard library.
- vonmoltke 13y agoI think you and I are reading the statement differently. I did not read it as he was using regex to parse the XML; I read it as he as using regex to parse the text contents of a particular tag that he extracted using a standard XML parser.
- buerkle 13y agoOf course regex is appropriate in some cases. You parse XML with a standard API, then use a regex on the contents of a single tag. For all we know, inside the tag could have been "img: foobar", regex works great in that case.