When I compile and match, for example:
pattern = re.compile(r""" ([a-z]|\d)+$ # ends with letter or number only """, re.VERBOSE | re.IGNORECASE)
print(re.match(pattern, 'abc'))
result is correct:
<_sre.SRE_Match object; span=(0, 3), match='abc'>
but then I use the same pattern with another string:
print(re.match(pattern, 'abc.fds'))
result is:
None
I tried to reformulate the pattern to the same, for example:
pattern = re.compile(r""" (a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|\d)+$ # ends with letter or number only """, re.VERBOSE | re.IGNORECASE)
or to:
pattern = re.compile(r""" [a-z\d]+$ # ends with letter or number only """, re.VERBOSE | re.IGNORECASE)
or to:
pattern = = re.compile(r""" ([a-z]|\d)+$ # ends with letter or number only """, re.VERBOSE | re.IGNORECASE)
but the result is all the time the same - None
And еhat is the double strange for the last three pattern - None is result also for
print(re.match(pattern, 'abc'))
I checked this patterns on the site regex101.com
and all of them should work good and right
It's achtung!
|