One of my favorite regular expression parlor tricks is this regular expression which matches collections with a prime number of elements in it.
/^(?!(.{2,})\1+$).+/
One of my favorite regular expression parlor tricks is this regular expression which matches collections with a prime number of elements in it.
/^(?!(.{2,})\1+$).+/
^ // At the start of a line
(?! // check if the following does **not** match (negative look-ahead)
( // create a capture group (group 1)
.{2,} // match 2 or more of any repeating character
) // end capture group (group 1)
\1+ // repeat matching capture group 1, one or more times
$ // match the end of the line
) // end negative look-ahead
.+ // match one or more characters
Technically it should be .{2,} at the end so we ensure we don't match a single element :)
Hope this helps! And thanks for watching my streams :)
@strf0x My absolute pleasure! :D
I love helping people with regular expression questions. They're like a fun game to me at this point xD