How to make REGEX(Regular Expression) Non Case sensitive in serviceNow?

omdave
Kilo Contributor

I have created one regex as Below in fix Script.

Here I need to check after @ ,MY-mobile.COM should be there.

Its working but as case sensitive

also i used (?i) but its not working in servicenow

My code Is Below:

var regex = /MY-mobile.COM(?!@)$/;

gs.print(regex.test('om.dave@MY-mobile.COM'));  // TRUE

gs.print(regex.test('om.dave@my-mobile.COM')); // False  (Case Sensitive )

Thanks in advance .

Thanks 

Om Dave

1 ACCEPTED SOLUTION

vitaly_sukharev
Kilo Guru

Hi Dave,

You should add "i" flag at the end of your regex, and mask the dot (cause otherwise the dot would match with any character) like this:

var regex = /MY-mobile\.COM$/i;
gs.print(regex.test('om.dave@MY-mobile.COM'));
gs.print(regex.test('om.dave@my-mobile.COM'));

//*** Script: true
//*** Script: true

View solution in original post

2 REPLIES 2

vitaly_sukharev
Kilo Guru

Hi Dave,

You should add "i" flag at the end of your regex, and mask the dot (cause otherwise the dot would match with any character) like this:

var regex = /MY-mobile\.COM$/i;
gs.print(regex.test('om.dave@MY-mobile.COM'));
gs.print(regex.test('om.dave@my-mobile.COM'));

//*** Script: true
//*** Script: true

Thanks Vitaly.