取两个字符串,例如aaaa和bbbb,我想要找到一个正则表达式,它将包含aaaa的每个字符串作为子字符串进行算术,但同时不包含bbbb。
答案 0 :(得分:1)
test = ['staaaap', 'nomatchaaaaabbbb', 'matchyaaaabbb']
for s in test:
m = re.match(r'(?!.*bbbb.*).*aaaa.*', s)
if m:
print('{} match: {}'.format(s, m.group(0)))
else:
print('{} no match'.format(s))
输出:
staaaap match: staaaap
nomatchaaaaabbbb no match
matchyaaaabbb match: matchyaaaabbb