Check if string matches pattern
One-liner: re.match(r"pattern", string) # No need to compile
import re>>> if re.match(r"hello[0-9]+", 'hello1'):... print('Yes')... Yes
You can evalute it as bool
if needed
>>> bool(re.match(r"hello[0-9]+", 'hello1'))True
Please try the following:
import rename = ["A1B1", "djdd", "B2C4", "C2H2", "jdoi","1A4V"]# Match names.for element in name: m = re.match("(^[A-Z]\d[A-Z]\d)", element) if m: print(m.groups())