Created
April 15, 2016 10:48
-
-
Save ryukinix/a9e6d774648555d8f4c6e57bef82cf2a to your computer and use it in GitHub Desktop.
Regex example of python n-digit number with n fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import random | |
def num_matcher(num, _len=6): | |
pattern = re.compile(r"^[0-9]{{{_len}}}".format_map(locals())) | |
return bool(pattern.match(num)) | |
value = random.randint(0, 1000000) | |
print(value) | |
print(num_matcher(str(value))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment