Pattern matching in Python Insightconnet workflow

144 Views Asked by At

I have a workflow that retrieves a CVE name and number. I can get it to print to Teams juts fine as is. However I am attempting to scrape ONLY the CVE number "CVE-2021-XXXXX"

When it runs as:

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)

I receive the following output:

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

I tried print() and Out as well.

It is in a loop so it will only be scraping one line of text at a time.

1

There are 1 best solutions below

1
Tim Biegeleisen On

Use re.findall here:

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']