Mathers
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
NateNate60@lemmy.world to Programmer Humor@lemmy.ml ·
edit-2
11 个月前

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

lemmy.world

message-square
80
fedilink
340

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

lemmy.world

NateNate60@lemmy.world to Programmer Humor@lemmy.ml ·
edit-2
11 个月前
message-square
80
fedilink

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

<answer>

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

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

  • Feathercrown@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    11 个月前

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

    • explore_broaden@midwest.social
      link
      fedilink
      arrow-up
      5
      ·
      11 个月前

      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.

      • Feathercrown@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        11 个月前

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

        • Ephera@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          11 个月前

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

          • Feathercrown@lemmy.world
            link
            fedilink
            English
            arrow-up
            3
            ·
            11 个月前

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

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

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: !programmerhumor@lemmy.ml

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.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 5 users / day
  • 361 users / week
  • 1.91K users / month
  • 8.1K users / 6 months
  • 1 local subscriber
  • 38.3K subscribers
  • 1.22K Posts
  • 14.8K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.4
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org