data = ['1. default, no hair, w/o glass',
'1. default, no hair, w/o glass',
'1. default, w/o hair, w/o glass',
'1. default, w hair, w/o glass']
def hair(line):
result = re.findall('(no|w/o|w)\s+hair', line)
if result:
return result[0] == 'w':
[hair(line) for line in data]
Look behind不支持可变宽度。在
向前看确实支持可变宽度。您可以:
Demo
我可以这样做:
输出:
^{pr2}$如果regex没有找到任何内容,则返回
None
。在re
模块不支持可变长度(零宽度)查找。在您需要:
修正了
hair
使用
regex
模块使用负前瞻的短函数:
相关问题 更多 >
编程相关推荐