From empirical data, it looks like O (n 2 ) .
I ran Ruby code on every 100th of the first 10,000 primes. Here are the results:

The blue dots are the recorded time, and the orange is y = 2.9e-9 * x^2 . The string matches the data perfectly, which means the complexity is O (n 2 ).
This is to be expected, as the regular expression checks all possible divisors to see if any of them are integers in the string.
source share