How does the regex expression that checks for prime numbers work? -


this question has answer here:

i found nice piece of regex code checks prime number. think understand i'm still little confused. here's code: /^1?$|^(11+?)\1+$/

can explain (step step) happening both regex code , how relates knowing if number prime or not?

the basic premise regular expression examines ones representation of number (e.g. 5 = 11111). checking presence of ones (1) in positions or groupings can identify number prime.

additional references:


Comments