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

original comic artist: thisstupidtwink@insta

    • jjj@lemmy.blahaj.zone
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 month ago

      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.

      • blueduck@piefed.social
        link
        fedilink
        English
        arrow-up
        0
        ·
        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)
        
      • trem@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        0
        ·
        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…

      • kartoffelsaft@programming.dev
        link
        fedilink
        English
        arrow-up
        0
        ·
        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.