• mystic-macaroni@lemmy.ml
    link
    fedilink
    arrow-up
    8
    ·
    10 hours ago

    Isn’t the whole point of regex to toil for 3 hours to write something very specific you will only ever use once?

    • Zarobi@aussie.zone
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      9 hours ago

      Isn’t the whole point of regex to toil for 3 hours to write something very specific you will only ever use once?

      /((?!([es]))y)(?:.*?)((?!(s))e)(?:.*?)(s)/
      
      Tap for spoiler

      It’s a Regex that checks if the letters for the word “yes” exists within a text in order. I call it the yesnometer

        • Zarobi@aussie.zone
          link
          fedilink
          English
          arrow-up
          3
          ·
          8 hours ago

          Nothing is wrong with that, but it will give you different output. I tend to like using capture groups just out of habit, it makes it more flexible and useful in future. Most of my co-workers hated Regex so I tried to make it easy for them.

          I also wanted the letters to be as close together as possible. In this example it doesn’t matter, but in other texts it might. Yours will find the first y, then the furthest possible e, then the furthest possible s. So you might get output where there’s a y on line 1 and the e s at the very end of the text. Nothing wrong with that, it’s just not what I was envisioning.

          Also it’s funnier in this context to have a complicated regex.