3 ms·
I know regex. But I use it so sparingly that every time I need it I forgot again the character for word boundary, or the character for whitespace, or the exact
by eddd-ddde 1y ago
I know regex. But I use it so sparingly that every time I need it I forgot again the character for word boundary, or the character for whitespace, or the exact incantation for negative lookahead. Is it >!? who knows.
A shortcut to type in natural language and get something I can validate in seconds is really useful.
- layer8 1y agoHow do you validate it if you don’t know the syntax? Or are you saying that looking up syntax –> semantics is significantly quicker than semantics –> syntax? Which I don’t find to be the case. What takes time is grokking the semantics in context, which you have to do in both cases.
- tough 1y agohttps://regex101.com/ https://regex101.com/
- marcosdumay 1y agoNotice that site has a very usable reference list you can consult for all those details the GP forgets.
- layer8 1y agoThat doesn’t answer the question. By “validate”, I mean “prove to yourself that the regular expression is correct”. Much like with program code, you can’t do that by only testing it. You need to understand what the expression actually says.
- widdershins 1y agoTesting something is the best way to prove that it behaves correctly in all the cases you can think of. Relying on your own (fallible) understanding is dangerous. Of course, there may be cases you didn't think of where it behaves incorrectly. But if that's true, you're just as likely to forget those cases when studying the expression to see "what it actually says". If you have tests, fixing a broken case (once you discover it) is easy to do without breaking the existing cases you care about. So for me, getting an AI to write a regex, and writing some tests for it (possibly with AI help) is a reasonable way to work.
- layer8 1y agoI don’t believe this is true. That’s why we do mathematical proofs, instead of only testing all the cases one can think of. It’s important to sanity-check one’s understanding with tests, but mere black-box testing is no substitute for the understanding.
- tough 1y agoCode is not perfect like math imho libraries some times make weird choices in theory theory and practice are the same, in practice not really in the context of regex, you have to know which dialect and programming language version of regex you’re targeting for example. its not really universal how all libs/languages works thus the need to test
- eddd-ddde 1y agoIn my case most of my regex is for utility scripts for text processing. That means that I just run the script, and if it does what I want it to do I know I'm done. LLMs have been amazing in my experience putting together awk scripts or shell scripts in general. I've also discovered many more tools and features I wouldn't have otherwise.