उदाहरण
रेगुलर एक्सप्रेशन के साथ 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