Skip to content

Instantly share code, notes, and snippets.

@hunterhector
Created November 15, 2014 17:19
Show Gist options
  • Save hunterhector/7f7b1714576abc6f8c3b to your computer and use it in GitHub Desktop.
Save hunterhector/7f7b1714576abc6f8c3b to your computer and use it in GitHub Desktop.
Regex Prime
#!/usr/bin/python
import re
def regex_prime(n):
l = "1" * n
return re.match(r"^1?$|^(11+?)\1+$", l) == None
while True:
n = raw_input("\nEnter a number and test for prime:")
try:
print(regex_prime(int(n)))
except ValueError:
print("not an integer\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment