Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 以下字符串需要正则表达式_Python_Regex - Fatal编程技术网

Python 以下字符串需要正则表达式

Python 以下字符串需要正则表达式,python,regex,Python,Regex,search?query=EasterGmPromo2020&searchType=mktgattribute&monet=CURATED&fulfillment=all 我有这种类型的字符串。我只想从?query=EasterGmPromo2020获取数据。如何在正则表达式中执行。这是一个查询字符串。有很多解析URL的包,这里不需要正则表达式 一种方法是使用urllib.parse(内置于Python 3中) 使用urllib.parse而不是regex。 from urllib import

search?query=EasterGmPromo2020&searchType=mktgattribute&monet=CURATED&fulfillment=all

我有这种类型的字符串。我只想从?query=EasterGmPromo2020获取数据。如何在正则表达式中执行。

这是一个查询字符串。有很多解析URL的包,这里不需要正则表达式

一种方法是使用
urllib.parse
(内置于Python 3中)


使用
urllib.parse
而不是regex。
from urllib import parse

params = parse.parse_qs("query=EasterGmPromo2020&searchType=mktgattribute&monet=CURATED&fulfillment=all")
print(params["query"])