What is the best way to remove non-digit characters from the beginning of a line?

Is javascript the best way to remove non-digit characters from the beginning of a line?

-_1234d5fr 

should ideally turn into

 1234d5fr 
+4
source share
2 answers
 str = str.replace(/^\D+/, ''); 
+6
source

What about...

 str = str.replace(/^[^0-9]+/, ''); 
+5
source

Source: https://habr.com/ru/post/1311544/


All Articles