面试题答案
一键面试import re
def extract_part(s):
good_pattern = re.compile(r'good_(\d{3})')
bad_pattern = re.compile(r'bad_([a-zA-Z]{3})')
good_match = good_pattern.match(s)
bad_match = bad_pattern.match(s)
if good_match:
return good_match.group(1)
elif bad_match:
return bad_match.group(1)
return None