let updateStreamSelectedCourse = 'mech (electronics)'.replace(/([^w]+)/g, '_', );
console.log(updateStreamSelectedCourse);
output should be mech_electronics
but now im geting output is mech_electronic_
let updateStreamSelectedCourse = 'mech (electronics)'.replace(/([^w]+)/g, '_', );
console.log(updateStreamSelectedCourse);
output should be mech_electronics
but now im geting output is mech_electronic_
2
Answers
You can’t replace them with different characters, but You can replace the last
_
with the following/_$/g,''
should be what you need :