How to extract specific text from string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:11 AM
Hello All,
I am trying to extract 'Severity 3' text from below string however unable to pull it:
START_REQUEST Test ticket
|
I am trying below expression but it's returning 'NULL' where I passed above email text to temp1 variable:
var regex = new SNC.Regex('/Sev\\d{7}/im');
var val = regex.match(temp1);
gs.info(">>>>>>" + val);
Please help.
Thank you,
Amit
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:17 AM
Hello Amit,
try like this:
var start = temp.indexOf("SEVERITY:");
var sev = temp.substring(start+9, start+19);
gs.print(sev);
Tested this and is printing "Severity 3".
hope this helps!
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:32 AM
Hi Amit
I assume your asking how to pull "Severity 3 " from the string
var temp1=" /DESCRIPTIONREF:TICKET#234566CATEGORY:ISSUE_TYPE:SERVICE:ASSIGNMENTGROUP:SEVERITY:Severity 3USER_NAME:PMAIL:test@test.comPHONE:-USER_LOCATION:-NUMBER_OF_IMPACTED_USERS:Single userENVIRONMENT:PRODUCTIONEND_REQUEST";
var regex = new SNC.Regex('/Severity 3/');
var val = regex.match(temp1);
gs.info(">>>>>>" + val);
This returns the string when the string "Severity 3" is present. If not it returns null.
Hope this helps!
Regards
Abi R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2022 10:21 AM
Thank you Abi.
This works but I need to write 4 different regex to capture severities. Is it possible to check for multiple severities in single Regex.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2023 08:05 AM
Hi @Amit41
Try this
// Get the text value from wherever it's stored (e.g. a variable or form field)
var textValue = "START_REQUEST\nSUMMARY:Test incident\nDESCRIPTION:Ticket created for Test User\n\nTest ticket\n\n\n/DESCRIPTION\nREF:TICKET#234566\nCATEGORY:\nISSUE_TYPE:\nSERVICE:\nASSIGNMENTGROUP:\nSEVERITY:Severity 3\nUSER_NAME:P\nMAIL:test@test.com\nPHONE:\nUSER_LOCATION:\nNUMBER_OF_IMPACTED_USERS:Single user\nENVIRONMENT:PRODUCTION\nEND_REQUEST:";
// Extract the Severity value using a regular expression
var severityMatch = textValue.match(/SEVERITY:(.*)/i);
var severity = '';
if (severityMatch) {
severity = severityMatch[1].trim();
}
// Use the Severity value in some way (e.g. set a form field value)
g_form.setValue('field_name', severity);