Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Email Regex to replace special characters with underscores

Sai122
Giga Guru

Hi, 

I want to convert all the special characters into the underscores. Any snipped will be helpful 

 

Thanks,

Sai

1 ACCEPTED SOLUTION

hvrdhn88
Giga Patron

try

 

var string ='@@!H';
string = string.replace(/[\W_]/g, "_");
gs.print(string);

View solution in original post

2 REPLIES 2

hvrdhn88
Giga Patron

try

 

var string ='@@!H';
string = string.replace(/[\W_]/g, "_");
gs.print(string);

Allen Andreas
Tera Patron

Hi,

Your post isn't too detailed for us to fully understand what you're meaning, but basically, you can use this to replace all special characters in a string to underscores:

var string = "field information here";
var test = string.replace(/[^\d\w]/gi, '_');

or...to check me...

var string = "I'mtheman(&*$#*&)@gmail.com";
var test = string.replace(/[^\d\w]/gi, '_');
gs.info(test);

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!