this post was submitted on 31 Oct 2024
329 points (97.1% liked)

Programmer Humor

32380 readers
1361 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

(page 2) 32 comments
sorted by: hot top controversial new old
[–] [email protected] 4 points 1 week 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.

[–] [email protected] 1 points 1 week ago (1 children)

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

load more comments (1 replies)
[–] [email protected] 4 points 1 week ago (4 children)

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

load more comments (4 replies)
[–] [email protected] 3 points 1 week ago (1 children)

Empty input Or input of exactly 1 character Or input of at least 2 characters, followed by at least 1 something (idk what \1 matches)

Did I get it (almost)?

[–] [email protected] 1 points 1 week ago* (last edited 1 week ago) (1 children)

\1 is group 1 which is inside (), so send part is repeated 2 or more times of 2 or more char.

load more comments (1 replies)
[–] [email protected] 3 points 1 week ago

Looks like APL to me.

[–] [email protected] 3 points 1 week ago

It matches “yo momma”.

[–] [email protected] 3 points 1 week ago

For a second I thought I was still in the thread about monkeys face-rolling typewriters until the heat death of the universe not eventually producing Hamlet

[–] [email protected] 2 points 1 week ago

The pipe is throwing me off because usually I have to do parentheses for that to work...

[–] [email protected] -2 points 1 week ago (3 children)

All my homies hate regexs. That's actually the best use case I found for LLMs so far : I just tell it what I want it to match or not match, and it usually spits out a decent one

[–] [email protected] 3 points 1 week ago

That sounds…

Easier to get almost right than actually learning the subject.

Much, much harder to get completely right than actually learning the subject.

So yes, basically the archetypal use case for LLMs.

load more comments (2 replies)
load more comments
view more: ‹ prev next ›