用于删除前导点的Javascript函数 [英] Javascript function to remove leading dot
本文介绍了用于删除前导点的Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有前导点的 javascript 字符串.我想使用javascript替换功能删除前导点.我尝试了以下代码.
I have a javascript string which have a leading dot. I want to remove the leading dot using javascript replace function. I tried the following code.
var a = '.2.98»';
document.write(a.replace('/^(\.+)(.+)/',"$2"));
但这行不通.有什么想法吗?
But this is not working. Any Idea?
推荐答案
以下内容将字符串开头的点替换为空字符串,字符串的其余部分保持不变:
The following replaces a dot in the beginning of a string with an empty string leaving the rest of the string untouched:
a.replace(/^\./, "")
这篇关于用于删除前导点的Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文