How to remove multiple leading and trailing commas from a string in Node.js

1 Answer

0 votes
let str = ',,,,,javascript,typescript,node.js,python,,,,';
 
str = str.replace(/^\s*,+\s*|\s*,+\s*$/g, '');
 
console.log(str);
 
   
   
   
   
/*
run:
   
javascript,typescript,node.js,python
   
*/

 



answered Jun 9, 2022 by avibootz
...