【发布时间】:2019-02-03 01:22:54
【问题描述】:
我有以下代码同时匹配第 1 行和第 2 行,我仅想匹配第 2 行但不匹配第 1 行,谁能提供有关如何执行此操作的指导?
import re
line1 = '''Revert "Revert <change://problem/47614601> [tech feature][V3 Driver] Last data path activity timestamp update is required for feature""'''
line2 = '''Revert <change://problem/47614601> [tech feature][V3 Driver] Last data path activity timestamp update is required for feature"'''
if re.findall(".*?(?:Revert|revert)\s*\S*(?:change:\/\/problem\/)(\d{8})", line2):
match = re.findall(".*?(?:Revert|revert)\s*\S*(?:change:\/\/problem\/)(\d{8})", line2)
print "Revert radar match%s"%match
revert_radar = True
print revert_radar
【问题讨论】:
-
line.startswith('Revert'} and line.count('Revert') == 1? -
不,这不适用于所有其他情况,我需要修复正则表达式,因为它也可以处理其他情况
-
可能在开头使用否定前瞻断言来排除不需要的行。
-
所有 unwanted 案例的结构是否相同?
word your looking for followed by a space followed by a double quote and the same word? -
它们是单独的行还是更大的正文中的行?
标签: python