I tried to remove string using nodejs
const replace = "1."
const replacer = new RegExp(replace, 'g', '')
function removeText() {
let originalText = '
1. I can own unlimited wealth on this earth
2. My potential for wealth knows no bounds
3. I attract limitless financial opportunities
';
let newText = originalText.replace(replacer, '');
console.log(newText);
}
removeText();
using this code I can only remove "1." but what about 2.
, 3.
, I have this counting upto 100, can someone help me?
3
Answers
I found the answer. There is a common pattern going on in the sentences, we want to remove all the numbers, and they all end up with a dot(.) in the end.
This code block will check wether the text starts with a number and ends up with a dot, if both of these conditions meet in a single text, then it will be removed from the string. Have a great day. ☺️
split the string by lines. Filter out the empty values. Split each line by number followed by dot and finally join them back with new line.
You can simply achieve this by just using digit
RegEx
.Live Demo :