Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须编写一些 JavaScript 代码来替换变量中的字符:
var data = "abcd.-3*(adsa3sd"
从变量data我必须替换0-9a-zA-Z和.字符。
data
0-9a-zA-Z
.
我希望输出为:
-*(
如何做呢?
简洁版本:
"abcd.-3*(adsa3sd".replace( /[\da-zA-Z.]+/g, '' ); >> "-*("
试试这个:
text.replace(new RegExp('[A-Z|a-z|0-9|\\.]','g'),"")摆脱那个。
text.replace(new RegExp('[A-Z|a-z|0-9|\\.]','g'),"")
使用text.replace(new RegExp('[A-Z|a-z|0-9|\.]','g'),"")wheretext是字符串对象。
text.replace(new RegExp('[A-Z|a-z|0-9|\.]','g'),"")
text