Doing this in SQL is absolute insanity. I’ve seen many pieces of code grow in this way and I understand how it happens but still surprises me to see how scrappy things are under the hood at some big-time companies.
Hello, what would be a better way to do it? In code? Regex?
Probably yes, in code with regex. To name a few advantages:
1. Better readability and organization. Rules and word lists can be abstracted to more of a config format.
2. possible to easily store in a database and support dynamic additions/changes to the rules and words
3. Better accountability of performance. Able to use profiling to catch any perf issues in the rules.
4. Testable with unit tests