linux – Why my test on using regex to determine the prime number fails?

I was learning regex, and i got to know that regex can determine whether a number is a prime number, the regex is as follow:

/^1?$|^(11+?)\1+$/

At First, i thought the “https://stackoverflow.com/” on the start and the end was useless, so i ignored it and made a test on my bash terminal, and got the wrong result unless i added the “https://stackoverflow.com/” on each side of the pattern.

i have read the grep manual and searched for google, but none of them solve the puzzle.

Below are the contrast test that i did
my test on bash
i tested 17(the prime number) ,only with the ‘/’ version that i get the correct result(Nothing print out), BUT then i found out that for every test number, if i add the “https://stackoverflow.com/”, it would not print anything even if the number is not a prime. On the other hand, without adding “https://stackoverflow.com/”, it would print the number even if the number is a prime num.

i am not a native English speaker, if there are some mistakes in my sentences, please forgive me.

if you can help me or give me some ideas , i would be very grateful.

Read more here: Source link