3 ms·
If by "raw text" you mean string values (i.e. the equivalent of text nodes in XML) I don't see this as being particularly difficult, I don't think I'd use a Reg
by arethuza 17y ago
If by "raw text" you mean string values (i.e. the equivalent of text nodes in XML) I don't see this as being particularly difficult, I don't think I'd use a Regex for it but then I wouldn't use a Regex to extract text from an XML document/stream either.
- mojuba 17y agoRegex are practical, you can use them from the command line, in your SQL statements, with your browser's JS engine, or on the server side - everywhere. A full Sexpr parser, on the other hand, is a more complicated machine not readily available everywhere. You don't have it in the UNIX userland by default, in SQL implementations, etc.
- prodigal_erik 17y agoStrings that look like text or markup may or may not be, depending on whether they are surrounded by comments, CDATA marked sections, or processing instructions. Most people who try this get it wrong, and end up with a tool that randomly fails on some documents. Getting it right requires a regex big enough to actually be an XML parser, and why write that from scratch rather than use one that's known to work (and understand well-formedness and namespaces as well)?