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

Programmer Humor

32710 readers
219 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 11 points 1 month 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 4 points 1 month 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.