3 ms·
Maybe I'm too old. I tend to think of a regex as either matching or not matching. Finding a bit of code that uses a capture to determine whether a match was fo
by rbobby 11y ago
Maybe I'm too old. I tend to think of a regex as either matching or not matching.
Finding a bit of code that uses a capture to determine whether a match was found seems like it would easily be confusing/inobvious.
Some pretty clear commenting and it would be ok... maybe.
Also... I wonder how well it would work as part of a larger regex, one that already uses captures (or non-capturing groups)? The examples are all nice, short and sweet... but how often do regex based solutions stay short and sweet? A few maintenance cycles/years and suddenly you've got this funky regex/capture thing that only Bob understands and he's way to busy to talk to you for 5 minutes... and once you change things then Bob suddenly finds time to review your code to complain how you broke it for such a simple change. There goes your bonus you told the wife you were sure to get so you could take her and the kids on vacation. The day after your divorce finalized Bob sends you a fix request to use that improved scheme of yours because the old regex one isn't flexible enough anymore.