Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Regex help request
-
I need to check wether the format of an input is "00 - 00 - 00" (12 characters without quotation marks) or not and then run block 1 or 2 based on result.
[0-9][0-9] - [0-9][0-9] - [0-9][0-9] won't do what I want if the input is, for example, "aaaa 00 - 00 - 00 aaa". I want to keep asking the user for input until the format is exactly 00 - 00 - 00, 12 characters.
Help?
-
Avoid regex like the plague that it is...
def validate(s='00 - 00 - 00'): parts = s.split(' - ') return len(parts) == 3 and all(len(p) == 2 and p.isdigit() for p in parts) # ----------------------- def validate_with_re(s='00 - 00 - 00'): return bool(re.search(r'^\d\d - \d\d - \d\d$', s))
-
Thank you, @ccc!