• @[email protected]
    link
    fedilink
    38 months ago

    For a second I thought I was still in the thread about monkeys face-rolling typewriters until the heat death of the universe not eventually producing Hamlet

    • @[email protected]
      link
      fedilink
      English
      10
      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”!<

        • @[email protected]
          link
          fedilink
          English
          38 months ago

          Only the part after the pipe character. The pipe character works as an “or” operator. RegalPotoo is right.

          • @[email protected]OP
            link
            fedilink
            38 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”.

            • @[email protected]
              link
              fedilink
              48 months ago

              I agree, you’re right about the part after the pipe and RegalPotoo’s explanation was not entirely correct.

          • @[email protected]
            link
            fedilink
            58 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.

    • @[email protected]
      link
      fedilink
      98 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>.

        • @[email protected]
          link
          fedilink
          58 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.

            • @[email protected]
              link
              fedilink
              3
              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.

                • @[email protected]
                  link
                  fedilink
                  28 months ago

                  That’s your opinion my man

                  I’m not gonna continue using arguments if all you can respond with is cynicism, apparently I wasn’t wrong about the elitism part

  • Captain Aggravated
    link
    fedilink
    English
    418 months ago

    knowing Matt Parker it only matches prime numbers or multiples of e or something.

    looks at <ansewer>

    Yeah see?

  • @[email protected]
    link
    fedilink
    38 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)?

    • @[email protected]
      link
      fedilink
      1
      edit-2
      8 months ago

      \1 is group 1 which is inside (), so second part is repeated 2 or more times of 2 or more char.

      • @[email protected]
        link
        fedilink
        18 months ago

        Interesting.

        So that means match any string that is made entirely of a single repeating sequence, where repititon is possible.

  • @[email protected]
    link
    fedilink
    18 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

    • @[email protected]
      link
      fedilink
      English
      38 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.

    • @[email protected]
      link
      fedilink
      68 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.

      • @[email protected]
        link
        fedilink
        18 months ago

        I’ve never had to use it for important stuff tbh. But alongside a regex tester and a sample of the stuff I intend to use it on, I’ve had good results with an incremental approach where I tell the LLM what I want to change with the expression until I’m satisfied

  • @[email protected]
    link
    fedilink
    128 months ago

    A non prime number of times… It looks like the string of characters could repeat number of times because the whole capture group repeats. I don’t see a prime constraint.

    • @[email protected]
      link
      fedilink
      English
      48 months ago

      The capture group must be the same each time it repeats, so the number of characters stays the same. So X groups of Y characters = string of length X*Y. X and Y can be anything so any string length that can be made by multiplying two numbers-- which is every non-prime string length-- is matched. 0 and 1 are handled specially at the start.

    • @[email protected]
      link
      fedilink
      58 months ago

      Yes, the first one matches only 2 more characters while the second matches 1 or more. Also the +? is a lazy quantifier so it will consume as little as possible.