diegosse diegosse - 5 months ago 29
Python Question

Using regex to check corrections of input

I'm trying to use regex to checking it's the same with input chars.

To be shorter, i'm writing char to the console and i need to check it with pattern. I must write for ex. 123-45-67-890 to go to the next operation. Any ideas?


This should works for pattern you need:

import re
def check (s) : return False if re.match('^\d{3}-\d{2}-\d{2}-\d{3}$', s )==None else True

>>> check ('123-4567-890')
>>> check ('123-45-67-890')