3 ms·
> Are you bad at regular expressions, but feel you could get away by just processing text with some loops and split statements? Don't. Use RegExes - every singl
by xyzzy_plugh 3y ago
> Are you bad at regular expressions, but feel you could get away by just processing text with some loops and split statements? Don't. Use RegExes - every single time until you are good at it.
I'm quite proficient with regular expressions but rarely reach for them outside of throwaway scripts. I'd much rather use some loops and split statements, frankly.
- jweatherby 3y agoAgreed. Early on, I would enjoy solving a problem with regex, but really, that's a code smell and a red flag beyond basic validation.
- znpy 3y agoDepends on the case, however... A few times i've seen a number of lines of code that was easily replaced with a single line of regexp matching and value extraction via named capture groups. The amount of code that comes out of "some loops and split statements" quickly turns into spaghetti code, especially when you need to extract values and/or reference what would be other capture groups. In my experience, as long as you provide (at least) one sample of the expected input, a regexp is essentially self-documenting.