Regex 用Python匹配字符串中的列表

Regex 用Python匹配字符串中的列表,regex,python-2.7,Regex,Python 2.7,我需要你的帮助。“matcherror”是一个列表,包含需要与“errormsg”匹配的错误代码列表。我想将“代理未被授权在预订时支付不足”与“errormsg”中提到的完整错误消息匹配,并忽略其他参数(即忽略总成本=10812.00000,总付款=10308)。事实上,“matcherror”中提到的任何内容都应与“errormsg”匹配忽略句子的其余部分 matcherror = ["['Connection Refused']","['Link Down']","['Agent is no

我需要你的帮助。“matcherror”是一个列表,包含需要与“errormsg”匹配的错误代码列表。我想将“代理未被授权在预订时支付不足”与“errormsg”中提到的完整错误消息匹配,并忽略其他参数(即忽略总成本=10812.00000,总付款=10308)。事实上,“matcherror”中提到的任何内容都应与“errormsg”匹配忽略句子的其余部分

matcherror = ["['Connection Refused']","['Link Down']","['Agent is not authorized to under pay on a booking.']"]
errormsg = "Agent is not authorized to under pay on a booking. Total Cost = 10812.00000, Total Payment = 10308"
事实上,我正在努力实现以下目标:

matcherror = ["['Connection Refused']","['Link Down']","['Agent is not authorized to under pay on a booking.']"]
errormsg = "Agent is not authorized to under pay on a booking. Total Cost = 10812.00000, Total Payment = 10308"
evaluate = matcherror in errormsg
if evaluate == True:
     send_email(showfailure)
else:
     print "No failure for this hour"

您需要更改求值。您在
字符串中搜索
列表
。而不是在
列表
上循环,并在
字符串
中查找其每个元素

import re
matcherror = ["['Connection Refused']","['Link Down']","['Agent is not authorized to under pay on a booking.']"]
errormsg = "Agent is not authorized to under pay on a booking. Total Cost = 10812.00000, Total Payment = 10308"
evaluate=False
for i in matcherror:
    if re.sub(r"^\['|'\]$","",i) in errormsg:
        evaluate=True
if evaluate == True:
     print "Fail"
else:
     print "No failure for this hour"
@恐惧矩阵