3 ms·
I'd want something like this and the more compact language. Classic regex syntax has a similar problem as purely expression-based languages: it's hard to clear
by ben509 6y ago
I'd want something like this and the more compact language.
Classic regex syntax has a similar problem as purely expression-based languages: it's hard to clearly delineate between smaller and larger scale structures.
Sometimes, brevity is clarity. It's bad to write matchDigit().times(2).match('-').matchDigit().times(2) instead of simply '\d\d-\d\d'. So even with the problems with metacharacters, I don't think you want to lose that.
But more complex regexes are clearest when the individual parts are assigned to meaningful names and they're then composed into the final expression.
Most regex implementations require that you're doing string-munging to compose regular expressions, and developers and maintainers must be aware of the semantics of that string-munging to the regex compiler.
Allowing the dev to compose regular expressions from parts, then, seems like the greatest opportunity here for improving regex syntax. It'd be especially helpful for any dynamically generated regular expression, and you could have facilities like a "quote" operator.