• S_H_K@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    No cookie for me I just tried it in Notepad++ and VS code and it matches lines of one characer (first group I think) or the starting of a line that is an at least 2 characters string repeated twice (second group it seems)
    so the second group matches abab
    abcabc abcdeabce abcdefabcdef

    Nothing about prime numbers really only first repetition gets a match. Very interesting Honestly I used regex from years and never had to retort to something like this ever. I can only imagine it useful to check for a password complexity to not be repeated strings like I do for sites that I just want in and use a yopmail.com mail to register a fake user.

    • NateNate60@lemmy.worldOP
      link
      fedilink
      arrow-up
      0
      ·
      8 months ago

      “at least 2 characters repeated [at least] twice” implies the string’s length is divisible by a number greater than 1.

  • fysihcyst@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    This is brilliantly disgusting.

    Literal interpretation of the regex

    The regex matches either a line with a single character or a line with a sequence of two or more characters that’s repeated two or more times. For some examples: the regex matches “a”, “b”, “abab”, “ababab”, “aaaa”, and “bbbbbb”, but does not match “aa”, “bb”, “aaa”, “ab”, “aba”, or “ababa”.

    Hint for the special thing it matches

    For a line with a single character repeated n times, what does matching (or not matching) this regex say about the number n?

  • PeriodicallyPedantic@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    Empty input Or input of exactly 1 character Or input of at least 2 characters, followed by at least 1 something (idk what \1 matches)

    Did I get it (almost)?

  • Sylvartas@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    All my homies hate regexs. That’s actually the best use case I found for LLMs so far : I just tell it what I want it to match or not match, and it usually spits out a decent one

    • BluesF@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      8 months ago

      Oooof. I feel like trying to figure out what’s wrong with some regex I didn’t write is much harder than writing it myself personally.

    • kibiz0r@midwest.social
      link
      fedilink
      English
      arrow-up
      0
      ·
      8 months ago

      That sounds…

      Easier to get almost right than actually learning the subject.

      Much, much harder to get completely right than actually learning the subject.

      So yes, basically the archetypal use case for LLMs.

    • RegalPotoo@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      8 months ago

      Something like

      !“A line with exactly 0 or 1 characters, or a line with a sequence of 1 or 3 or more characters, repeated at least twice”!<

          • NateNate60@lemmy.worldOP
            link
            fedilink
            arrow-up
            0
            ·
            8 months ago

            They said—

            A line with exactly 0 or 1 characters, or a line with a sequence of 1 or 3 or more characters, repeated at least twice

            Note—

            …or a line with a sequence of 1 or 3 or more characters, repeated at least twice

            It should be—

            …or a line with a sequence of 2 or more characters, repeated at least twice

            The regex in the post will match “abab”. Their original description (line 2 of this comment) will not match “abab”.

          • gwilikers@lemmy.ml
            link
            fedilink
            arrow-up
            0
            ·
            8 months ago

            Yeah, I’ve found myself wasting quite a lot of time thinking of the ‘perfect regex’ for task X only to realise that I could have avoided doing so by simply taking a different approach.

        • ddplf@szmer.info
          link
          fedilink
          arrow-up
          0
          ·
          8 months ago

          And then a few more any time you actually want to use it.

          And then double it each time you have to decipher the existing one

          Just don’t use regex unless there is really no other way, and when you absolutely have to - frankly, that’s one of the ultra rare occasions I recommend using the AI.

            • ddplf@szmer.info
              link
              fedilink
              arrow-up
              0
              ·
              edit-2
              8 months ago

              That I do, yes, because that’s a small chunk of code that - when necessary - would have to be completely remade anyways, not just modified.

    • Speiser0@feddit.org
      link
      fedilink
      arrow-up
      0
      ·
      8 months ago

      Regular expressions in general, and automata theory, sure you should know about that. But a specific extended regex language like here? That’s like saying you’re shit at coding if you can’t do <insert arbitrary programming language here>.

  • SpiceDealer@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    I could be wrong but I think the ‘(…+?)’ portion will either remover a dud or replenish the allowance.