我有一个字符串
'request=1417935385131095&to%5B%5D=596254125&to%5B%5D=683330370&e2e=%7B%22submit_0%22%3A1394711375644%7D'
我希望数据在"&到%5B%5D = 596254125&到%5B%5D = 683330370&"
即。我想要596254125和683330370。
如何通过rejex
获取我试过这个
map = re.split(r"&to%5B%5D=\d+&", request)
这不起作用。你能告诉我我做错了吗?
答案 0 :(得分:7)
当有dedicated function解析网址查询字符串时,请不要使用正则表达式:
from urlparse import parse_qs
map = parse_qs(request)
to = map['to[]']
演示:
>>> from urlparse import parse_qs
>>> request = 'request=1417935385131095&to%5B%5D=596254125&to%5B%5D=683330370&e2e=%7B%22submit_0%22%3A1394711375644%7D'
>>> map = parse_qs(request)
>>> map['to[]']
['596254125', '683330370']