রেগুলার এক্সপ্রেশন, split() এবং join() ব্যবহার করে স্ট্রিং থেকে অতিরিক্ত কমা ও স্পেস সরিয়ে ফেলা যায়।
উদাহরণ
var sentence = "My,,,,,,, Name,,,, is John ,,, Smith";
console.log("Before removing extra comma and space=" + sentence);
sentence = sentence.split(/[\s,]+/).join();
console.log("After removing extra comma and space=");
console.log(sentence);
কমান্ড: node fileName.js
আউটপুট
PS C:\Users\Amit\JavaScript-code> node demo133.js Before removing extra comma and space=My,,,,,,, Name,,,, is John ,,, Smith After removing extra comma and space= My,Name,is,John,Smith