Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript remove leading number label from string

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!

like image 392
Chris Dutrow Avatar asked May 04 '11 04:05

Chris Dutrow


People also ask

How to remove leading zeros JavaScript?

To remove the leading zeros from a number, call the parseInt() function, passing it the number and 10 as parameters, e.g. parseInt(num, 10) . The parseInt function parses a string argument and returns a number with the leading zeros removed. Copied!

How do I strip a number from a string in Javascript?

To remove all numbers from a string, call the replace() method, passing it a regular expression that matches all numbers as the first parameter and an empty string as the second. The replace method will return a new string that doesn't contain any numbers.

How to remove a value from string in JavaScript?

Method 2: Using replace() method with a regular expression: This method is used to remove all occurrences of the specified character, unlike the previous method. A regular expression is used instead of the string along with the global property. It will select every occurrence in the string and it can be removed.

How to remove specific word from string in JavaScript?

Method 1: Using replace() method: The replace method can be used to replace the specified string with another string. It takes two parameters, first is the string to be replaced and the second is the string which is replacing from the first string.


1 Answers

str = str.replace(/^\d+\.\s*/, '');
like image 52
alex Avatar answered Nov 09 '22 00:11

alex