正则表达式的if-else习语
matchstate的Python项目详细描述
匹配状态
这个包提供了一个习惯用法:
importrefromtypingimportMatch,UnionfrommatchstateimportMatchStatem=MatchState()# type: Union[MatchState, Match]ifm.match(re.compile(r'apple'),'applx'):print('apple:',m.group())elifm.match(r'orange','orange'):print('orange:',m.group())else:print('No match')
或者您可以直接使用matchstate类。