Aug-15-2022, 10:19 PM
This should work.
>>> import re >>> >>> s = 'BG13TPPV1234B' >>> r = re.search(r"\w+\d{2}TPPV\d+[BC]", s) >>> r.group() 'BG13TPPV1234B' >>> >>> s = 'BG13TPPV9999C' >>> r = re.search(r"\w+\d{2}TPPV\d+[BC]", s) >>> r.group() 'BG13TPPV9999C' >>> >>> s = 'BG13SPPV1245B' >>> r = re.search(r"\w+\d{2}TPPV\d+[BC]", s) >>> r.group() Traceback (most recent call last): File "<interactive input>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'group'