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.
如果我有以下情况:
(8
有没有办法在8不拆分的情况下从中取出数字?使用parseInt退货NaN。parseInt有没有忽略非数字的替代方法?
8
parseInt
NaN
parseInt(str.replace(/[^\d]/g, ''), 10)
您可以使用快速正则表达式来匹配该数字,并且只需预先+转换为数字:
+
var num =+ '(8'.match(/\d+/)