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:从字符串中去除非数字字符
字符串匹配让我很头疼。
例子:
如果我有这样的字符串:
abc123xyz456()* ^%$111u222
然后将其转换为:
123456 111222
正则表达式呢?
尝试类似的东西:
'abc123xyz456()*'.replace(/\D/g,'')
<input id='num' value='hgjhGJHGt7y67ihgGUT&6tb.,.,z.oy8'/> $('#num').val($('#num').val().replace(/[^\d]/g, ""));