第一次发现JavaScript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个匹配的字符. 而str.replace(/\-/g,"!")则可以全部替换掉匹配的字符(g为全局标志). replace() The replace() method returns the string that results when you replace text matching its first argum…
替换字符串中的数字 var text = "abc123"; text=text.replace(/[0-9]/ig,""); 此时得到的text为"abc". 替换字符串中的非数字 var text = "abc123"; text=text.replace(/[^0-9]/ig,""); 此时得到的text为"123". i表示区分大小写. g表示进行全局匹配.…