Nice (abuse of regexp) !
AFAICT the way the string is going to be parsed is equivalent to this:
def isprime(n):
if n == 0 or n == 1:
return False
i = 2
while i <= n:
if (n - i) % i == 0:
return False
i += 1
return True
A parser implementation may optimize and do "while (n - i) >= 1" instead, which cuts in half the number of iterations.