Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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,-- 大家好, 我需要一个人帮我做下面的正则表达式。 字符串类似于: str = 'value=\"20\" />\r\n\t\r\n<\/div>","whatiwant":"<div id=\"whatiwant\">\r\n\t\r\n\t\t<\/div>","idontwanthat":"<div id=\"idontwanthat\">\r\n\t\r\n\t blablalblalblalbla \t\r\n\t\t\t<

--

大家好,

我需要一个人帮我做下面的正则表达式。 字符串类似于:

str = 'value=\"20\" />\r\n\t\r\n<\/div>","whatiwant":"<div id=\"whatiwant\">\r\n\t\r\n\t\t<\/div>","idontwanthat":"<div id=\"idontwanthat\">\r\n\t\r\n\t blablalblalblalbla \t\r\n\t\t\t<\/div>"'
附言:我可以有其他部门在这个部门

感谢您对我的任何帮助

尝试使用-

这将匹配文本
“whatiwant”:
,然后匹配双引号
中的任何内容(即使是空字符串)

如果要提取div的html代码,可以检索第一个组的值:

matches=re.findall(r'"whatiwant":"(.*?[^\\])??"', mstr)
for match in matches:
    html= match.group(1)

html解析器更适合于此。这真的是你的字符串还是网页的一部分?嗨,jerry,我知道,但是字符串不适合html解析器。我将使用一个用于我想要的div
\"whatiwant\":.*(?=,\".*?\"\:)
"whatiwant":"(.*?[^\\])??"
matches=re.findall(r'"whatiwant":"(.*?[^\\])??"', mstr)
for match in matches:
    html= match.group(1)