ServiceNow server side regex reference

 https://docs.servicenow.com/en-US/bundle/sandiego-application-development/page/script/general-scripting/concept/c_RegularExpressionsInScripts.html

 

 e.g.

var sRegexQ='/<small>(.*?)</small>/';
var pattern= new SNC.Regex(sRegexQ);


 var sStr='<h3>OPEN Problem P-22061362 in environment <i>Non Production</i></h3><br><small>Problem detected at: 10:27 (UTC) 09.06.2022</small><hr><b>1 impacted infrastructure component</b><hr><br><div><span>Process</span><br>';

var results = pattern.match(sStr);
       while (results !== null) {
               gs.print("match: " + results[0]);
               results = pattern.match();
       }

*** Script: match: <small>Problem detected at: 10:27 (UTC) 09.06.2022</small>
 
or if use sRegexQ='/(?<=\<small\>)(\s*.*\s*)(?=\<\/small\>)/'
 *** Script: match: Problem detected at: 10:27 (UTC) 09.06.2022

 =====================

var r = new SNC.Regex('/world/');
var str = 'helloworld';
var replaced = r.replaceAll(str, 'there');
// replaced == 'hellothere'

 

(ServiceNow )

Comments

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage