Welcome to Regex Licensing!
Licensing the Regular Expression Because you shouldn’t be adding a regular expression to a code base without a license. And those who have licenses generally know it’s a better idea not to use them.
A brief summary of typical disasters:
- Parsing email or IP addresses
- Replacing build time tokens
- Rolling your own string interpolations
- Validating a person’s name
- Parsing a phone number
- Validating a street number
- Enforcing a zip code globally
- Searching in a database for something in a live query
- Parsing a date or a time
- Basically almost always outside of command line or ad-hoc query fu
Let’s be clear - ad-hoc regex use is fine. Your grep is safe. We won’t talk about when you were searching for that thing in that text file.
The main reason you don’t want to use a regex in production is that you’re hurting developer reasoning for anyone who tries to read your code. I’ve lost count of the number of code reviews I’ve witnessed where a dev will be carefully reviewing a contribution line by line only to see a regex and go, “oh, I’m sure that’s fine” and skip right on. Their compactness obscures their complexity and in real world code, they make fantastic hiding places for serious show stopping bugs and their “write once / read never” reputation is well deserved.