I want to create a python function that takes a word as argument and uses regular expression package re
to reject words that contain any character other than '0123456789:MF' and '\s'.
Structure:
def function(word):
pattern = re.compile('REGEXHERE')
if pattern.match(word):
return True
else:
return False
The problem is that I do not know the regular expression that does just that.
SOLUTION
Since I can't answer my own question yet, I publish here the solution provided by @MartinBonner that worked just fine:
def function(word):
return not re.compile('[^0-9::MF\\s]').search(word)