您可以使用 JavaScript 中的正则表达式来替换字符串中的数字。请看如下代码:
let str = "Hello, my name is 123456.";
let result = str.replace(/\d+/g, "X");
console.log(result);
// 输出:Hello, my name is X.
这里,我们定义了一个字符串 str,并使用 replace 方法将所有的数字替换为字母 "X"。正则表达式 /\d+/g 表示匹配一个或多个数字。
|
|
另类的冲锋衣 · SSM框架,MyBatis-Plus的学习( ...· 1 年前 · |
|
|
精明的手套 · java - Consider ...· 3 年前 · |
|
|
叛逆的木瓜 · 使用Hibernate进行大数据量的性能测试 ...· 3 年前 · |
| javascript js js代码 js截取字符串 |
| https://juejin.cn/s/js%E6%9B%BF%E6%8D%A2%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E7%9A%84%E6%95%B0%E5%AD%97 |
|
|
英勇无比的金鱼
3 年前 |