This is my attempt
def matcher(ex):
if re.match(r'^[\w|\d][A-Za-z0-9_-]+$', ex):
print 'yes'
My goal is to match only submission that satisfy all the followings
- begins with only a letter or a numeric digit, and
- only letter, space, dash, underscore and numeric digit are allowed
- all ending spaces are stripped
In my regex, matcher('__')
is considered valid. How can I modify to achieve what I want really want? I believe \w
also includes underscore. But matcher('_')
is not matched...