match() এবং split() ব্যবহার করে কমার পরের নির্দিষ্ট শব্দ ও বাকি অংশ মুছে ফেলা যায়।
উদাহরণ
var sentence = 'My Name is John, Smith I live in US';
console.log("The original value=" + sentence);
var expression = sentence.match(/([^,]*)(.*)/)[1];
var positionForComma = sentence.match(/([^,]*),(.*)/)[2].split(' ')[1];
var newValue = expression + ', ' + positionForComma;
console.log("Updated=" + newValue);
কমান্ড: node fileName.js
আউটপুট
PS C:\Users\Amit\javascript-code> node demo175.js The original value=My Name is John, Smith I live in US Updated=My Name is John, Smith