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

Harsh Vardhan
Giga Patron

try

 

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

View solution in original post

2 REPLIES 2

Harsh Vardhan
Giga Patron

try

 

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

Allen Andreas
Administrator
Administrator

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!