we have a string like this:
const a = `3. n Trust me - I know about these thins.`;
the 3. n
part can be any number. and we want to remove it from the beginning of the string so one way is simply doing this:
const a = `3. n Trust me - I know about these thins.`;
console.log(a.replace('3. n', '').trim())
As you see the issue is using this approach we need to change the number each time to remove it from the sting.
The desired result would be:
"Trust me - I know about these thins."
How would you do this?
2
Answers
You can replace the string with
/^d+.s*/
.Where:
^
asserts the start of the string.d+
matches one or more digits..
matches the period character.s*
matches zero or more whitespace characters.Demo:
You can try this regex
/^[0-9]+.s+/