15 YouTube views, likes subscribers in 10 minutes. Free!
Get Free YouTube Subscribers, Views and Likes

How on Earth does ^.?$|^(..+?)1+$ produce primes?

Follow
Stand-up Maths

Take your personal data back with Incogni! Use code standupmaths at the link below and get 60% off an annual plan: https://incogni.com/standupmaths

^.?$|^(..+?)\1+$

Props will be for sale here: https://www.ebay.co.uk/usr/standupmaths

Fantastic blog post by Illya Gerasymchuk. "Demystifying The Regular Expression That Checks If A Number Is Prime" https://illya.sh/thecodeumentaryblo...

Thanks to everyone who has sent in history about this regex. Seems it was written ≥25 years ago by a Perl programmer named Abigail.

Cheers to viewer Dave Cross who found this earliestknown mention in a 2000 blog post: http://test.neilk.net/blog/2000/06/01...

Thanks to viewers Chris Lawrence and Jimmy Diep for suggesting the topic.

Huge thanks to my Patreon supporters. They keep me supplied with all the primes I need.   / standupmaths  

CORRECTIONS
Several people have corrected me that regex is zero indexed it’s just that \0 refers to the entire matched string.
Mike Salisbury ands others have pointed out that the leftmost column in the table of repeated wild cards shouldn't be included. Otherwise the length of the string could match a single prime length.
At 6:07 I say "Begins and end with an m" when I meant ends with an “s”. No one has corrected that mistake with more vigour than viewer Timur Sultanov.
There is some concern about my pronunciation of rejex.
Let me know if you spot anything else!

Filming, VFX and editing by Alex GennBash
Written and performed by Matt Parker
Extra material by Sam Hartburn
Number yeeting by Lucie Green
Spooky lighting and producing by Nicole Jacobus
Music by Howard Carter
Design by Simon Wright and Adam Robinson

MATT PARKER: Standup Mathematician
Website: http://standupmaths.com/

posted by 4cluvq