Let’s say the following are our strings with commas −
"My Favorite subject is," "My Favorite subject is, and teacher name is Adam Smith" "My Favorite subject is, and got the marks 89"
To replace commas, use replace and in that, use Regular Expression. Following is the code −
To run the above program, you need to use the following command −
Here, my file name is demo164.js.
This will produce the following output −
- Related Articles
- Replace parts of a string with C# Regex
- How to trim commas with MySQL?