var reg=/\\|\/|\?|\?|\*|\"|\“|\”|\'|\‘|\’|\<|\>|\{|\}|\[|\]|\[|\]|\:|\:|\.|\^|\$|\!|\~|\`|\|/g; var temp = value.replace(reg,""); 以上正则表达式可以替换 斜杠.反斜杠.?.*.[].[].!.~.`.^.$.!.:等特殊字符,包含windows文件命名不能出现的所有特殊字符…
替换字符串中的数字 var text = "abc123"; text=text.replace(/[0-9]/ig,""); 此时得到的text为"abc". 替换字符串中的非数字 var text = "abc123"; text=text.replace(/[^0-9]/ig,""); 此时得到的text为"123". i表示区分大小写. g表示进行全局匹配.…
第一次发现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…