REGEX: /^1?$|^(11+?)+$/
1 is prime
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111
11111111111
111111111111
1111111111111
11111111111111
111111111111111
1111111111111111
11111111111111111
111111111111111111
1111111111111111111
11111111111111111111
111111111111111111111
1111111111111111111111
11111111111111111111111
111111111111111111111111
1111111111111111111111111
11111111111111111111111111
111111111111111111111111111
1111111111111111111111111111
11111111111111111111111111111
111111111111111111111111111111
1111111111111111111111111111111
11111111111111111111111111111111
111111111111111111111111111111111
1111111111111111111111111111111111
11111111111111111111111111111111111
111111111111111111111111111111111111
1111111111111111111111111111111111111
11111111111111111111111111111111111111
111111111111111111111111111111111111111
1111111111111111111111111111111111111111
11111111111111111111111111111111111111111
111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

<?php //demo/prime_regex_unary.php
/**
 * https://twitter.com/fermatslibrary/status/1671867903069626370
 */
ini_set('display_errors'TRUE);
error_reporting(E_ALL);
echo 
'<pre>';

$rgx "/^1?$|^(11+?)\1+$/";
echo 
PHP_EOL htmlentities("REGEX: $rgx");
for (
$n 1$n <= 100$n++) {
    
$num str_repeat('1'$n);
    echo 
PHP_EOL $num;
    if (
preg_match($rgx"$num")) echo " is prime";
}
echo 
PHP_EOL;
highlight_file(__FILE__);