I have a string like
aaa:::sss vvv ggg 4 SF 20 @text box2323
and i want to replace all non alphanumeric characters with single underscore. Like this :
aaa_sss_vvv_ggg_4_SF_20_text_box2323
What i tried so far is :
let nameRegex = new RegExp("[^a-zA-Z0-9_]","g");
let originalName="aaa:::sss vvv ggg 4 SF 20 @text box2323";
let finalName= originalName.toLowerCase().replace(nameRegex, "_");
console.log(finalName);
but what i am getting is :
aaa___sss_vvv_ggg_4_SF_20__text_box2323
As you can see i am getting 3 underscores at first replacement. I want single here.
Any help will be appricitated.