You could try the below string.replace
function. Use ^
to tell the regex engine to do the matching operation from the start. By putting 0
and .
inside a character class would match either 0 or dot.
string.replace(/^[0.]+/, "")
Example:
> "0.015.000".replace(/^[0.]+/, "")
'15.000'
> "0.150.000".replace(/^[0.]+/, "")
'150.000'
> "015.000".replace(/^[0.]+/, "")
'15.000'
0
solved Javascript remove leading zeros and decimal points from string [closed]