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

original comic artist: thisstupidtwink@insta

  • Dæmon S.@catodon.rocks
    link
    fedilink
    arrow-up
    9
    ·
    4 days ago

    !onehundredninetysix@lemmy.blahaj.zone TIL, through a meme (yep, memes can be very teaching, too), that I can reuse capture groups in a recurring manner inside a RegExp (I didn’t know about the \(number) thing, but I readily inferred, due to past experience with using \(number) in KDE Kate’s Regexp replace, it had something to do with “this position must contain the nth group verbatim”, opened the DevTools, tried .match with a fixed version of the meme’s regex (i.e. without the invalid spaces) and a random phone sequence my mind conjured out of thin air, and voilá, the slash-number thing indeed behaved as I guessed it would behave). So… Thanks to whoever made the meme because TIL thanks to you!

    /^Be( )not\1(a)fr\2id$/ (Biblically-accurate RegExp).

    • kartoffelsaft@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      3 days ago

      This is a cool feature of a lot of regex implementations but I will warn you that reusing capture groups in a match means it’s impossible for any regex engine to guarantee a reasonable upper bound (best they can do is O(n!) I think? I’d have to look up the details). In a replacement string this is a non-issue because there’s no way they can recurse out of control.

      Edit: found the video I originally heard this from: https://www.youtube.com/watch?v=gITmP0IWff0