Reputation: 51
I have this string "00-12.50" and I would like to remove the leading zeros with and replace with a blank space. How do I do that?
My Regex example is not working: strDedAmount.replace(/^[0]*/, ' ')
This example returns " 0-12.50" Thanks
Upvotes: 0
Views: 211
Reputation: 1131
I suppose using the "with callback" version of string.replace(regex, callback) will serve you well
const str = '00-12.50'
const fixed = str.replace(/^0+/, match => ' '.repeat(match.length))
console.log(fixed)
Upvotes: 1