Pricefield | Lemmy
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
@[email protected] to Programmer [email protected] •
edit-2
7 months ago

Oh boy what a beautiful regex. I'm sure it does something logical and easy to understand.

lemmy.world

message-square
83
fedilink
320

Oh boy what a beautiful regex. I'm sure it does something logical and easy to understand.

lemmy.world

@[email protected] to Programmer [email protected] •
edit-2
7 months ago
message-square
83
fedilink

^.?$|^(..+?)\1+$

<answer>

Matches strings of any character repeated a non-prime number of times

https://www.youtube.com/watch?v=5vbk0TwkokM

  • @[email protected]
    link
    fedilink
    English
    4•7 months ago

    Is there a reason to use (..+?) instead of (.+) ?

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

      • @[email protected]
        link
        fedilink
        English
        3•7 months ago

        Ah, didn’t know +? was lazy, thanks

        • Ephera
          link
          fedilink
          3•7 months ago

          I thought, the +? was going to be a syntax error. 🙃

          • @[email protected]
            link
            fedilink
            English
            3•7 months ago

            I was like, why specify “one or more” and then make it optional? Isn’t that just .*?

Programmer [email protected]

[email protected]
Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 24 users / day
  • 93 users / week
  • 164 users / month
  • 1.61K users / 6 months
  • 4 subscribers
  • 1.76K Posts
  • 37.8K Comments
  • Modlog
  • mods:
  • @[email protected]
  • @[email protected]
  • UI: 0.18.4
  • BE: 0.18.2
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org