import re m = re.match('..', 'Y') result = 'match' if m else 'nothing' print(result) code example
Example: re module documentation
>>> m = re.search(r'(?<=-)\w+', 'spam-egg')
>>> m.group(0)
'egg'
>>> m = re.search(r'(?<=-)\w+', 'spam-egg')
>>> m.group(0)
'egg'