【发布时间】:2021-12-09 10:50:31
【问题描述】:
import re
def extraction(parentTag):
should_retain = True
for imageTag in parentTag:
if re.search("^(\d+.+\d)",imageTag) and not re.search("^(\d+.+\d[-^]\w)",imageTag) and not re.search("^(\d+.+\d[-^]\d)",imageTag):
should_retain = False
break
if should_retain:
return parentTag
return None
expected_input = [
['419adf7', '1.0.22-SNAPSSHOT'],
['1.0.24', '82e13c1', 'master'],
['1.0.25-1618314650'],
['1.0.10', '7ad4886'],
['1.0.13-1589279873', 'e597811'],
['73a3788'],
]
expected_input = list(filter(None,list(map(extraction, expected_input))))
print(expected_input)
电流输出 = [['1.0.25-1618314650'], ['1.0.13-1589279873', 'e597811']]
预期输出 = [['1.0.25-1618314650'], ['1.0.13-1589279873', 'e597811'], ['419adf7', '1.0.22-SNAPSSHOT'], ['73a3788'] ]
还有没有更好的方法来编写代码以使用正则表达式获得预期输出。
【问题讨论】: