python从字符串中提取指定的内容

    有如下字符串:

text=cssPath:"http://imgcache.qq.com/ptlogin/v4/style/32",sig:"OvL7F1OQEojtPkn5x2xdj1*uYPm*H3mpaOf3rs2M",clientip:"82ee3af631dd6ffe",serverip:"",version:"201404010930"

    怎么提取元素为sig的值?就是OvL7F1OQEojtPkn5x2xdj1*uYPm*H3mpaOf3rs2M

1 import re
2 
3 s = 'text=cssPath:"http://imgcache.qq.com/ptlogin/v4/style/32",sig:"OvL7F1OQEojtPkn5x2xdj1*uYPm*H3mpaOf3rs2M",clientip:"82ee3af631dd6ffe",serverip:"",version:"201404010930"'
4 
5 res = re.findall(r'sig:"([^"]+)"',s)
6 print(res)
7 print(res[0])

运行结果如下:

['OvL7F1OQEojtPkn5x2xdj1*uYPm*H3mpaOf3rs2M']
OvL7F1OQEojtPkn5x2xdj1*uYPm*H3mpaOf3rs2M

 

转载于:https://www.cnblogs.com/sxinfo/p/10392510.html

你可能感兴趣的:(python从字符串中提取指定的内容)