I mean one would typically insert it as a literal in another language but if there are flexible macros it could be done without any runtime cost/standard reinventing.
There is Backus-Naur form (and it’s derivatives), which at least lets you name each section of text like you would a variable or function. Technically matches context-free expressions rather than regular ones but that’s hardly different for most cases.
Ugh I don’t miss having to parse someone else’s regex at my old job.
Is there a version of regex with comments?
I mean one would typically insert it as a literal in another language but if there are flexible macros it could be done without any runtime cost/standard reinventing.
PCRE supports inline comments:
foo(?# match literal foo)\d+Also verbose mode
pattern = re.compile(r""" ^ # start of string [A-Z]{2} # two uppercase letters \d{4} # four digits $ # end of string """, re.VERBOSE)There is Backus-Naur form (and it’s derivatives), which at least lets you name each section of text like you would a variable or function. Technically matches context-free expressions rather than regular ones but that’s hardly different for most cases.
I’ve seen attempts of regex pre-processors, where you’d get some builder API like:
pattern .digits(3) .literal(" - ")Can’t use that in configurations, though, unless you template the configuration, I guess…
Emacs has the rx macro: https://www.gnu.org/software/emacs/manual/html_node/elisp/Rx-Notation.html