I'm confused. How are those two related? Case statements can replace if statements and can be used for exhaustiveness checking. Regexes are for parsing strings.
I'm confused. How are those two related? Case statements can replace if statements and can be used for exhaustiveness checking. Regexes are for parsing strings.
The benefit is that the regex library costs a lot in hidden complexity - debugging why a particular regex works slowly or eats lots of memory is hard. If a similar problem pops up in hand written code, you can use your standard profilers and other tools to see what's happening.
So you either drag this complexity into your code or dump it on the regex library. It's a trade-off.
I encountered one of these once. A user decided to enter this in the middle of their post:
------------------------------
It triggered catastrophic backtracking, and IIRC, 16 characters was right around where you could see noticeable delay, then at about 19 was when it ran so long it never returned.So managing a bunch of hard-coded code paths via a switch instead of using a regex to pattern-match.
It's less future-proof, but even an entry-level dev can reason about a switch statement and update it as needed.