且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 JavaScript 中从字符串中去除所有非数字字符

更新时间:2023-02-22 15:37:20

使用字符串的 .replace 方法,其正则表达式为 D,它是匹配所有非数字的速记字符类:

Use the string's .replace method with a regex of D, which is a shorthand character class that matches all non-digits:

myString = myString.replace(/D/g,'');