I have some strings that look like this:
1. Some stuff 2. some more stuff ... 26. Even more stuff
What is a good way to remove the leading number labels on these strings in javascript?
(Each line is a separate string in a separate variable)
Thanks!
I have some strings that look like this:
1. Some stuff 2. some more stuff ... 26. Even more stuff
What is a good way to remove the leading number labels on these strings in javascript?
(Each line is a separate string in a separate variable)
Thanks!
Share Improve this question asked May 4, 2011 at 4:27 Chris DutrowChris Dutrow 50.4k67 gold badges195 silver badges262 bronze badges 1 |6 Answers
Reset to default 8str = str.replace(/^\d+\.\s*/, '');
var s = "26. Even more stuff";
s.replace(/^[0-9]+/g, '')
"123. some text".match(/^[0-9]+\.\s+(.*)$/)[1] // "some text"
You can use a regular expression that matches the beginning of the string, any number of digits, the period and the white space after it:
s = s.replace(/^\d+\.\s+/, '');
This will leave the string unchanged if it would happen to look differently.
Just this line:
s = "26. Even more stuff";
s = s.replace(/^[^.]+\./, "")
OUTPUT
Even more stuff
str = "2. some more stuff";
str = str.replace(/[0-9]+.\s+/, "");
str.replace(/\d+\./g,'')
are each line in a seperate string? – Ibu Commented May 4, 2011 at 4:32