this post was submitted on 31 Oct 2024
325 points (97.7% liked)

Programmer Humor

32361 readers
52 users here now

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

Rules:

founded 5 years ago
MODERATORS
 

^.?$|^(..+?)\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 4 days ago (1 children)

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 4 days 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.