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

Programmer Humor

32472 readers
828 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
[–] S_H_K@lemmy.dbzer0.com 4 points 2 weeks ago (1 children)

No cookie for me I just tried it in Notepad++ and VS code and it matches lines of one characer (first group I think) or the starting of a line that is an at least 2 characters string repeated twice (second group it seems)
so the second group matches abab
abcabc abcdeabce abcdefabcdef

Nothing about prime numbers really only first repetition gets a match. Very interesting Honestly I used regex from years and never had to retort to something like this ever. I can only imagine it useful to check for a password complexity to not be repeated strings like I do for sites that I just want in and use a yopmail.com mail to register a fake user.

[–] NateNate60@lemmy.world 1 points 2 weeks ago (1 children)

"at least 2 characters repeated [at least] twice" implies the string's length is divisible by a number greater than 1.

[–] S_H_K@lemmy.dbzer0.com 1 points 2 weeks ago

Yes but the match goes for the first repetition the rest of the string isn't matched no matter the length, again don't find anything about prime numbers unless I checked something wrong. There is another guy who got it right it seems.