正则问题,notebpad可以匹配,match却不行。

line = '{"from":"zh","to":"en","trans_result":[{"src":"\u6bcf\u5929\u90fd\u5728\u953b\u70bc\u4f46\u5230\u5e95\u54ea\u4e2a\u65f6\u6bb5\u5065\u8eab\u6700\u6709\u6548\u5462?","dst":"Exercise every day, but which period is the most effective exercise?"}]}'
#
# str_line = str(line)
#
# json_line = json.loads(line)
#
# new_result = json_line["trans_result"][0]["dst"]
#
# print(new_result)

print(re.findall('"dst":"(.*)?"',line)[0])

match方法不行,就用 这个findall()方法。


猜你喜欢

转载自blog.csdn.net/Cincinnati_De/article/details/80319485