字符串变量respPostJson为:
,url : 'http:\/\/hi.baidu.com\/shuisidezhuyi\/item\/d32cc02e598460c50e37f967',
使用代码:
foundUrlList = re.findall("url\s*?:\s*?'(?P<url>http:\\/\\/hi\.baidu\.com\\/.+?\\/item\\/\w+?)'", respPostJson); logging.info("foundUrlList=%s", foundUrlList);
却搜不到对应的字符串,结果为:
foundUrlList=[]
而只有给斜杠前面加上反斜杠:
foundUrlList = re.findall("url\s*?:\s*?'(?P<url>http:\\\/\\\/hi\.baidu\.com\\\/.+?\\\/item\\\/\w+?)'", respPostJson); logging.info("foundUrlList=%s", foundUrlList);
才可以搜索到结果:
foundUrlList=['http:\\/\\/hi.baidu.com\\/shuisidezhuyi\\/item\\/d32cc02e598460c50e37f967']
很是奇怪。目前不知道为何会这样,等待高手给解释解释。