我一定把我的正则表达式搞砸了。我试图在下面的str中找到ID和值(最终还需要找到description和它的值):
"cve": {
"CVE_data_meta": {
"ASSIGNER": "cve@mitre.org",
"ID": "CVE-2020-1785"
},
"data_format": "MITRE",
"data_type": "CVE",
"data_version": "4.0",
"description": {
"description_data": [
{
"lang": "en",
"value": "Mate 10 Pro;Honor V10;Honor 10;Nova 4 smartphones have a denial of service vulnerability. The system does not properly check the status of certain module during certain operations, an attacker should trick the user into installing a malicious application, successful exploit could cause reboot of the smartphone."
}
]
},
但由于某种原因,我收到了上面的错误消息
这是我的代码:
m= re.match("ID"\s*"([A-Za-z0-9-]*)"", str)
if m:
print (m.groups())
我在https://pythex.org/中测试了
ID:“([A-Za-z0-9-]*)”
工作正常,但在程序中运行它时分号有问题,因此我尝试用\s*替换它,但行延续有问题。有什么想法吗?现在我只需要捕获ID,然后需要描述
希望你能帮助我!我是python新手,不经常使用正则表达式
您已经关闭了“ID”之后的字符串,而紧随其后的反斜杠(在字符串外部)是行连续字符。错误是在行继续之后,您需要换行,但这当然不是您想要的
我认为您可以通过将外部引号转换为单引号来解决这个问题,如
'ID"\s*"([A-Za-z0-9-]*)"'
相关问题 更多 >
编程相关推荐