ServiceNow REGEX: get a string between 2 characters
in this example, grab a string between first and second **
var stext ="## OPEN Problem P-xxxxx in environment *Non Production*\n\nProblem detected at: 10:42 (UTC) 26.05.2022\n\n---\n**1 impacted infrastructure component**"; //--OPTION 1: var sArr=stext.split("*"); gs.print('option1 result'+sArr[1]); //OPTION 2: var first=stext.indexOf("*"); gs.print(first); var second=stext.indexOf("*", first+1); gs.print(second); var mySubString = stext.substring(first+1, second); gs.print('option2 result:'+mySubString );
var stext ="## OPEN Problem P-xxxxx in environment *Non Production*\n\nProblem detected at: 10:42 (UTC) 26.05.2022\n\n---\n**1 impacted infrastructure component**"; //--OPTION 1: var sArr=stext.split("*"); gs.print('option1 result'+sArr[1]); //OPTION 2: var first=stext.indexOf("*"); gs.print(first); var second=stext.indexOf("*", first+1); gs.print(second); var mySubString = stext.substring(first+1, second); gs.print('option2 result:'+mySubString );
Comments
Post a Comment