Regex Query for automation

Hey folks,
How did u put the following statement/condition in a single regex:-
CVE-4212-3234
CVE-1232-22223
CWE-111
CWE- 99

Try the following regex

(^[A-Z]{3}(-|.|\s)(\d*)(-|\s|.)(\d*)$)

1 Like

Regex Pattern: [A-Z]{3}(-\d±\d+|-\d+|- \d+)

Annotation 2020-02-26 130843

2 Likes

Hi,

I suppose CVE means “Common Vulnerabilities and Exposures” and CWE means “Common Weakness Enumeration”.
If so, the following pattern will be better.

(CVE-\d{4}-\d+|CWE-\s*\d+)

Regards,

Guyz, thank you all for your help.
I am using an automation for mail parsing purpose. I have an IP that needs to be forwarded, the regex condition of which is specified.
With all the regex statements provided, the bot is able to distinguish CVE, not the IP, where it treats both CVE and IP the same.
Could you pls help here.
IP’s are in - 0.0.0.0, 123.123.123.123, 12.12.12.12 in such formats.

@kadiravan_kalidoss
is this statement valid?:-
System.Text.RegularExpressions.Regex.Matches(item.Body,"[A-Z]{3}(-\d±\d+|-\d").Count>0
getting issues with the syntax

@Rushi_Muni So you need to identify IP Address in Email Body ?

small correction: “)” this is missing

regex.Matches(inputStr,"[A-Z]{3}(-\d±\d+|-\d)").Count>0

try this.!

@supermanPunch Yes

@Rushi_Muni I guess I had already Suggested an Answer in a Previous post of yours , didn’t that help :sweat_smile:

@supermanPunch
It has helped, but the bot is not able to distinguish both IP and CVE and treating them the same.
What should be done to differentiate them

@Rushi_Muni Can you give us a Sample Data for the Case when both the CVE and IP’s match with that Regex, We can find the difference and give you an Updated one

Sample CVE and CWE are:-

CVE-4212-3234
CVE-1232-22223
CWE-111
CWE- 99

Sample IP’s:-

123.21.32.1
0.0.0.0
12.23.1.22
1.2.111.1

Regex for IP used:- System.Text.RegularExpressions.Regex.Matches(item.Body,"\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b").Count>0

Regex for CVE used:-
System.Text.RegularExpressions.Regex.Matches(item.Body,"[A-Z]{3}(-\d±\d+|-\d)").Count>0

Here’s where the bot is not able to differentiate.

@Yoichi

Arigato :slight_smile: