用问号实现可选匹配 有时候,想匹配的模式是可选的。就是说,不论这段文本在不在,正则表达式都会认为匹配。字符?表明它前面的分组在这个模式中是可选的。 import re batregex = re.compile(r'Bat(wo)?man') mo = batregex.search('The Adventures of Batman') print(mo.group()) mo1