3 ms·
> You don't need fancy features to pattern-match a number. You would be surprised. If by a number you don't mean just a sequence of digits, and includes say f
by IlliOnato 6y ago
> You don't need fancy features to pattern-match a number.
You would be surprised.
If by a number you don't mean just a sequence of digits, and includes say floating point numbers, a regex to match it surprisingly complex.
Most of what I do with regexes (or similar constructs) is processing text. Extracting information from human-produced text, mostly. No, a parsed won't help me.
And, contrary to common belief, even processing XML (more precisely, XML fragments) sometimes makes more sense to do with regexes than with a parser. Specifically, when dealing with so-called "mixed contents", which is basically is just text with XML elements used for face markup.
For example, suppose you need to find in a text an ordinal number, that can look like "5<sup>th</sup>".
Of course it can be at the top level, as in "My 5<sup>th</sup> text", or within other face markup, as in "My <i>2<sup>nd</sup> italic</i> text", perhaps nested, as in "My <b><i>2<sup>nd</sup></b> italic</i> text".
Matching it using a parser while handling all these possibilities is hellishly difficult and verbose. With regexes it's straightforward and compact.
Parser is great what what you dealing is true hierarchical, or when you don't care much about what's marked up (e.g. transforms). When dealing with what's essentially is just rich text, it's much less helpful.
- madflame991 6y agoNow I'm genuinely curious: I want to see the fancy features used when writing a regex for floating point numbers :)