3 ms·
Oh ho ho ho… this is good. Anything that breaks apart regexes to make them easier to read and comment each logical unit is worth the extra lines and syntax. Th
by Waterluvian 4y ago
Oh ho ho ho… this is good. Anything that breaks apart regexes to make them easier to read and comment each logical unit is worth the extra lines and syntax. This is killer.
- bawolff 4y agoThere have been many attempts at doing this over the decades. It never catches on. I don't think its something developers really want.
- schoen 4y agoIt looks like this particular one has had some staying power, because it (or the PCRE version mentioned elsewhere in the comments) have been rather widely implemented. I didn't know about this and was a happy regular expression user without it, but this looks like a good feature for the specific use case of wanting other people to understand the structure of your regular expressions. And much more portable than I would have expected.
- semiquaver 4y agoStrongly disagree. I’ve seen this pattern used heavily inside many ruby codebases, it’s incredibly useful for making regular expressions readable(ish)
- NavinF 4y agoI’ve been doing this for years. Splitting up regexes and reusing sub-patterns is very common in new code.
- atoav 4y agoI am a developer and I really want it. For the next longr regex I am going to use it for sure, as I like to use f-strings extensively already.
- perceptronas 4y agoI suggest you take a look at parser combinators. They are quite readable compared to regexes
- bawolff 4y agoSo is SNOBAL. i don't disagree that long regexes are difficult to read only that real programmers dont really value that compared to conciseness (in practise anyways, people always claim to value readability, but their actions often differ)
- hans1729 4y agoI queried google for '"SNOBAL" acronym' and am no wiser than before, what do you mean? Also, I like to think of myself as a "real" programmer and I take great care to produce readable code :-)
- puzzlingcaptcha 4y agoParent comment probably meant SNOBOL.
- hans1729 4y agoThank you. For the uninitiated: https://en.wikipedia.org/wiki/SNOBOL https://en.wikipedia.org/wiki/SNOBOL see the second paragraph.
- rocqua 4y agoThey are totally different solutions. A regex is just a fast, usually integrated into the language, universally understood way to do some simple parsing. Parser combinators are an amazing specialized tool for building parsers, but one that is generally harder to integrate into a code-base (outside of e.g. Haskell), requires lesser known libraries, and is a paradigm that people need time to get used to. It's like saying people shouldn't use a mitre-box [1] and instead use a full fledged circular mitre-saw [2]. Yes the second tool is much more versatile, powerful and useful. But it requires much more setup, skill and investment to actually use. [1] https://en.wikipedia.org/wiki/Mitre_box https://en.wikipedia.org/wiki/Mitre_box [2] https://www.toolstation.com/power-tools/mitre-saws/c317 https://www.toolstation.com/power-tools/mitre-saws/c317
- otikik 4y agoThey might not see the value when they are writing a new regex, but they’ll miss it when they are reading an existing one.