whole = []
count = 0
with open(filename) as fin:
for eachline in fin:
pa = re.compile(r'"content":\s?"(.*?","\w)')
for s in pa.findall(eachline):
s = s[:-4]
s_fix = s.replace("\"","")
eachline = eachline.replace(s,s_fix)
data = json.loads(eachline)
whole.append(data)
我使用了一种可能的解决方案:
正如@jornsharpe所说,你最好还是清理一下源头。
也就是说,如果您不能控制额外的引号来自何处,您可以使用
(*SKIP)(*FAIL)
,使用新的regex
模块和neg。像这样看:见a demo on regex101.com。
在
Python
中: ^{pr2}$相关问题 更多 >
编程相关推荐