Once possible solution is the following:
" Hi @raju how do you do? ".replace(/\s+|[@\?]/g,'-')
.replace(/--+/g,'-')
.replace(/^[\s-]+|[\s-]+$/g,'')
>> output: "Hi-raju-how-do-you-do"
You can add any other ‘special’ chars to the []
in the first replace.
1
solved Regular Expressions:JavaScript