उदाहरण
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