我正在尝试解析各种类似这样的字符串
cpd00015\U c+cpd00041\U c+cpd00095\U c-->;2.0 cpd00001\U c+cpd00009\U c+cpd00067\U c
现在我有一些代码可以找到第一个实例,但是我想找到这些实例的所有实例。你知道吗
try:
found = re.search('cpd(.+?)_c', reactionEquation).group(1)
print(found)
except AttributeError:
# AAA, ZZZ not found in the original string
pass # apply your error handling
那个检索函数只查找此的第一个实例。有没有研究过你不完全知道名字的多个字符串?你知道吗
要获取所有匹配项,请使用
re.findall
例如:
输出:
只需将
search
更新为find all
并删除组。你知道吗相关问题 更多 >
编程相关推荐