retrieve the Service value from the text input

  Kiến thức lập trình

Need to extract the value from the text input which will be in following format:

Tom Felton ([email protected]) notified you about this incident:
Incident : TESTING INTEGRATION - P1
Status: active | Severity: SEV-1 | Service: Test Service 1 | Commander: Tom Felton
https://app.testapp.com
`your text`

From above text we want to fetch the value of the Service.
How can we use regular expression to get the Service value.

I tried using following script:

var msg = incGR.description;  //msg variable holds the input text
//var re = /Severity:s([0-9])/g;
// var m = re.exec(source.text_only_msg);
var regex = /Service: s([a-zA-Z0-9])/g;
var m = msg.match(regex);
// If there is no match, m will be null;
if (m) {

    if (m.length == 2) {
        severity = m[1];
    }
}
gs.info("severity: "+ severity); //printing Service here

1

LEAVE A COMMENT