python字符串匹配规则

闲来无事,总结下python的字符串匹配

1.从左到右依次匹配
a={"message":"","id":"123"}
a=json.dumps(a)
b="'mess"
c=b in a   True
2.中间有任意不匹配的字符都不会匹配成功
3.带有空格不能匹配成功

#结果返回结果校验函数
def check_res(res_excepts,res):
    '''
    返回结果和预期结果校验
    :param res_excepts: 传入id=123;a=4的字符串,以;分割
    res:    返回结果
    :return:
    '''
    res = res.replace('": "', "=").replace('":"', '=').replace('": ', '=').replace('":','=')
    print(res)
    for res_expect in res_excepts.split(';'):
        if res_expect not in res:
            return "failed"
    return "pass"

  

  

  

posted on 2017-01-19 16:07  xc-suibijilu  阅读(247)  评论(0编辑  收藏  举报

导航