the original said reggae but i misread it as regex and got this idea lol

original comic artist: thisstupidtwink@insta

you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 1 month ago (4 children)

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.

  • source
  • parent
  • hideshow 8 child comments
  • [–] 6 points 1 month ago

    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)
    
  • source
  • parent
  • [–] 2 points 1 month ago

    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...

  • source
  • parent
  • [–] 2 points 1 month ago

    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.

  • source
  • parent