Help on regex expression

Chiranjeevi K
Tera Expert

We have a integation from one servicenow instance orchestration as middle ware, and built an functionality with BR as such when incident is created in INSTANCE1 the description of the incident should be pass over to the incident will be creating in INSTANCE 2

REGEX expression using:

 var Description;
  var Description_temp;

    var SsnTaxID = /(([^+]\d{2}[-. ]\d{7}(?!\d\d))|(\d{3}[-. ]\d{2}[-. ]\d{4})|(\D\d{9}\D))/g;
    var charsAllowed = /[^a-zA-Z0-9.,?\|\^<>:;'!@#$%&*()"\/+=\-_`~{}\[\]\\\n ]/g;

    Description_temp = current.description.toString().replace(SsnTaxID, "removed SSN/TAX ID");
    Description = Description_temp.toString().replace(charsAllowed, "");

YOur expertize and help will be much appreciated, Thanks in advance !!
3 REPLIES 3

J Siva
Tera Sage

Hi @Chiranjeevi K 
What help you really need? You didn't mention why you are using the regex ?
Kindly provde more information.
Regards,
Siva

Ankur Bawiskar
Tera Patron
Tera Patron

@Chiranjeevi K 

share the API response and what you want from that and want to extract?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nishant8
Giga Sage

Hello @Chiranjeevi K, Although I'm not sure, I'm assuming that you are trying to replace a sensitive information with a fixed string - 'removed SSN/TAX ID', if so, then this output should be fine .

But, if you'd like to print only that sensitive information and remove other string then you can try to match than replace as below:

 var Description, tmp1;
var Description_temp;
var SsnTaxID = /(([^+]\d{2}[-. ]\d{7}(?!\d\d))|(\d{3}[-. ]\d{2}[-. ]\d{4})|(\D\d{9}\D))/g;
var charsAllowed = /[^a-zA-Z0-9.,?\|\^<>:;'!@#$%&*()"\/+=\-_`~{}\[\]\\\n ]/g;
Description_temp = current.description.toString().match(SsnTaxID) || [];
tmp1 = Description_temp.toString().match(charsAllowed) || [];
Description = Description_temp.concat(tmp1).join("");

 

Regards,

Nishant