336
submitted 2 weeks ago* (last edited 2 weeks ago) by NateNate60@lemmy.world to c/programmerhumor@lemmy.ml

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

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

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

you are viewing a single comment's thread
view the rest of the comments
[-] nroth@lemmy.world 12 points 2 weeks 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.

[-] Feathercrown@lemmy.world 4 points 2 weeks 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.

this post was submitted on 31 Oct 2024
336 points (98.0% liked)

Programmer Humor

32476 readers
573 users here now

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

Rules:

founded 5 years ago
MODERATORS