python - Python Insightconnet 工作流程中的模式匹配
问题描述
我有一个检索 CVE 名称和编号的工作流。我可以让它按原样打印到 Teams 中。但是我试图只抓取 CVE 编号“CVE-2021-XXXXX”
当它运行为:
import re
text ="{{["Get Vulnerability Content from Rapid7 Vuln DB"].[content_result].[title]}}"
m = re.search(r'CVE-\d{4}-\d{4,7}', text)
if m:
found = m.group(1)
我收到以下输出:
rapid7/Python 3 Script:2.0.3. Step name: run
Input: (below)
{}
Function: (below)
import re
text ="Google Chrome Vulnerability: CVE-2021-XXXX "Long description"
m = re.search(r'CVE-\d{4}-\d{4,7}', text)
if m:
found = m.group(1)
Could not run supplied script. Error: no such group
我也尝试了 print() 和 Out。
它处于一个循环中,因此一次只会抓取一行文本。
解决方案
在这里使用re.findall
:
text = 'Google Chrome Vulnerability: CVE-2021-XXXX "Long description"'
matches = re.findall(r'\bCVE-\d{4}-\w{4,7}\b', text)
print(matches) # ['CVE-2021-XXXX']
推荐阅读
- windows - 如何使继承的 AUTOLOAD 用于非方法工作?
- moodle - 如何为 Moodle Mobile 应用程序扩展 Moodle 插件
- javascript - Discord JS,回复某个用户ID
- javascript - 从电子表格中搜索数据并使用 google web app 脚本以 html 形式显示
- javascript - 如何在 Progressive Web Apps 中的浏览器内存储离线存储永久数据?
- git - 如何使下一个 git 提交准确地代表另一个提交的项目状态而不合并?
- node.js - Node.js Twitter Bot 返回错误:错误的 Twitter 流请求:410
- react-native - 导航到一个屏幕 tp 另一个
- sql - 尝试编写查询以获取帖子和相关附件的列表
- android - 根据 Android 设备中的 AdMob,这可以接受吗?