- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 07:01 AM - edited 11-24-2023 07:29 AM
This is my input string:
31/Jul/22 \\ Asset: \\ *.rock.com \\ Weakness: Information Disclosure \\ CVSS Score: \\ CSVSS Vector: ABCD:3.0/XX:X/XX:X/XX:X \\ URL: \\ Summary: \\ Severity: low
This is my BR:
// Get the input string parameter
function extractWords(inputString, pattern) {
var match = inputString.match(pattern);
return match ? match[1].trim() : "No match found";
}
// Define the regular expression patterns
var vectorPattern = new RegExp(/Vector: (.*?)(?: \\|$)/);
var assetPattern = new RegExp(/Asset: \\\\ (.*?)(?: \\|$)/);
var severityPattern = new RegExp(/Severity: (.*?)(?: \\|$)/);
// Extract words using the functions
var extractedVectorWords = extractWords(inputString, vectorPattern);
var extractedAssetWords = extractWords(inputString, assetPattern);
var extractedSeverityWords = extractWords(inputString, severityPattern);
current.dns = "/ " + extractedAssetWords;
gs.addInfoMessage("VECTOR : " + extractedVectorWords);
gs.addInfoMessage("ASSET : " + extractedAssetWords);
gs.addInfoMessage("SEVERITY : " + extractedSeverityWords);
The regular expression for Severity is not working in BR where as it works in Background script and other places. What is the problem?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 08:37 PM
There might be a chance of new line characters at the end of string, can you try the following RegEx for Severity.
/Severity: (.*?)(?: \\|$|\n|\r)/
Please mark my answer helpful and accept as a solution if it helped 👍✅
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 07:55 PM
@vidhya_mouli Did you check if the inputString in BR contains the
Severity: low
Verified the regular expression and it works just fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 08:37 PM
There might be a chance of new line characters at the end of string, can you try the following RegEx for Severity.
/Severity: (.*?)(?: \\|$|\n|\r)/
Please mark my answer helpful and accept as a solution if it helped 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 09:12 PM
Thank you. It worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 08:38 PM
HI @vidhya_mouli ,
// Get the input string parameter
function extractWords(inputString, pattern) {
var match = inputString.match(pattern);
return match ? match[1].trim() : "No match found";
}
// Define the regular expression patterns
var vectorPattern = new RegExp(/Vector: (.*?)(?: \\|$)/);
var assetPattern = new RegExp(/Asset: \\\\ (.*?)(?: \\|$)/);
// Updated the regular expression pattern for Severity
var severityPattern = new RegExp(/Severity: (.*?)(?: \\|$)/);
// Extract words using the functions
var extractedVectorWords = extractWords(inputString, vectorPattern);
var extractedAssetWords = extractWords(inputString, assetPattern);
var extractedSeverityWords = extractWords(inputString, severityPattern);
current.dns = "/ " + extractedAssetWords;
gs.addInfoMessage("VECTOR : " + extractedVectorWords);
gs.addInfoMessage("ASSET : " + extractedAssetWords);
gs.addInfoMessage("SEVERITY : " + extractedSeverityWords);
I trust you are doing great.
Please find the updated code as given below :
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi