| ▲ | rhdunn an hour ago | |||||||
Various libraries (e.g. Python's `re` library) support comments and whitespace as an option allowing you to format the regex on multiple lines with commenting to document what each part does. I'm not sure if there are any regex libraries that support DSLs and easy composability (e.g. the email RFC regex would be easier to read/maintain if you could specify the individual parts like are defined in the RFCs). | ||||||||
| ▲ | klibertp 26 minutes ago | parent | next [-] | |||||||
Emacs/Elisp has the rx library: https://www.gnu.org/software/emacs/manual/html_node/elisp/Rx... You get s-exp-based regex syntax (example for C-style block comments; there are shorter aliases too, e.g. `zero-or-more` can be written as `*`):
and you have rx-define and rx-let to defined named subforms:
And this is just the regex builder - syntactic sugar - as it still just builds a single regex serialized to a normal string.I tend to use it everywhere, since it is guaranteed to always properly escape all backslashes (a major pain point in string regexes in Emacs), but it's also useful for building larger regexes from chunks and reusing chunks in multiple related regexes.* | ||||||||
| ▲ | frizlab 29 minutes ago | parent | prev | next [-] | |||||||
Swift even has a `RegexBuilder` DSL which makes writing regular expressions pure code and type-safe. Pretty amazing tbh | ||||||||
| ▲ | AussieWog93 an hour ago | parent | prev [-] | |||||||
I honestly never knew that, should give it another go. | ||||||||
| ||||||||