python 匹配字符串中的双引号
{"index":0,"upstream":"test","name":"192.168.1.20:10285","status":"up","rise":231302,...
{"index": 0, "upstream": "test", "name": "192.168.1.20:10285", "status": "up", "rise": 231302, "fall": 0, "type": "http", "port": 0}, 怎么把这行字符串中test后的IP地址和端口号匹配出来
展开
1个回答
展开全部
直接使用eval函数,将字符串作为命令执行,就可以得到一个字典
s = '{"index": 0, "upstream": "test", "name": "192.168.1.20:10285", "status": "up", "rise": 231302, "fall": 0, "type": "http", "port": 0}'
d = eval(s)
print(d["name"])
# 192.168.1.20:10285
追问
{ "upstream": "test", "name": "192.168.1.20:10285", "status": "up", }
{ "upstream": "real", "name": "192.168.1.22:10285", "status": "up", }
多条日志,匹配出upstream为“test”的日志中的name中的ip地址端口?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询