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

From Standup Mathematician.

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+$

Fantastic blog post by Illya Gerasymchuk. "Demystifying The Regular Expression That Checks If A Number Is Prime" https://illya.sh/the-codeumentary-blog/regular-expression-check-if-number-is-prime/

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. https://www.patreon.com/standupmaths

CORRECTIONS
– None yet, let me know if you spot anything!

Filming, VFX and editing by Alex Genn-Bash
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: Stand-up Mathematician
Website: http://standupmaths.com/