I fell over a video on YouTube demonstrating a regular expression that could check if a numbers was a prime.
The video is entitled: "How on Earth does ^.?$|^(..+?)\1+$ produce primes?", well it does not really produce primes it just checks them anyway, fascinating video.
This is the regex:
^.?$|^(..+?)\1+$
And it Perl form:
^ # beginning of line of line
.?
$ # end of line
| # or
^ # beginning of line of line
(..+?)\1+
$ # end of line