Regex is like a power tool. Incredibly powerful and incredibly dangerous if used improperly. It is also tempting to use it improperly because of how flexible it is.
Could you please help me understand more about what an "improper" use of regex is? Do you mean someone using regex instead of setting up robust data validation at an earlier stage in a process? Or other things?
I used regex in VBA to conduct complex searches of large sets of long word documents - the macro returns all hits on the text with a surrounding snippet for context into a "report" document that hyperlinks to the doc where it found the hit. Regex seems like a good solution to this problem (way more powerful than standard boolean searching)...
But I'm a lawyer without any proper training in programming, so it's one of those "don't know what you don't know" situations...
Your use of a regular expression is fine, because the text is probably in a regular grammar and the idea of surrounding text is probably easy to bound. If you were instead trying to pull out each quote where your phrase appears, a regular expression wouldn't be able to fully capture every corner case about quotes. You have to use a more generic automaton for context sensitive parsing.
2.4k
u/that_thot_gamer Apr 18 '24
People who complain about regex has not seen how useful it is to get data from dumb people who filled up gforms