[英]Javascript - Removing leading zeros from a string of negative number
I have this string "00-12.50" and I would like to remove the leading zeros with and replace with a blank space. 我有此字符串“ 00-12.50”,我想删除前导零并替换为空白。 How do I do that?
我怎么做?
My Regex example is not working: strDedAmount.replace(/^[0]*/, ' ')
我的Regex示例无法正常工作:
strDedAmount.replace(/^[0]*/, ' ')
This example returns " 0-12.50" Thanks 本示例返回“ 0-12.50”谢谢
I suppose using the "with callback" version of string.replace(regex, callback) will serve you well 我想使用“ with callback”版本的string.replace(regex,callback)会很好地为您服务
const str = '00-12.50' const fixed = str.replace(/^0+/, match => ' '.repeat(match.length)) console.log(fixed)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.