DEV Community

Discussion on: Why Regular Expressions Are Super Powerful, But A Terrible Coding Decision

Collapse
 
moopet profile image
Ben Sinclair

Anything that's parsable data should be parsed with a parser. that makes sense.

But regular expressions don't need to be complicated just because they're complex; you can write them across several lines and add named groups and comments to every part. That's probably easier to maintain than a great list of individual conditions, like, if (string.startsWith('foo') && string.endsWith('bar')) { and so on.

Collapse
 
mwrpwr profile image
Joseph Maurer

Writing regular expressions is an art for sure. I’ve seen ones that are written extremely well (multiple lines, named capture groups, etc) but it doesn’t help if the input schema is always changing and requiring the regular expression to be re-written.

Collapse
 
moopet profile image
Ben Sinclair

If that's the case, then nothing helps!