1. 程式人生 > >正則問題,notebpad可以匹配,match卻不行。

正則問題,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()方法。