在JavaScript 中,剪切字符串有很多种方式。在本文中,我们将介绍一些常见的方法。 方法一:使用 substring 方法 substring 方法可以用来剪切指定索引之间的字符串。它接受两个参数,分别是要剪切的开始索引和结束索引。 const str = "Hello World"; const newStr = str.substring(0,5); console.log(newStr); // ...
使用正则表达式/[^\d]+/(替换与\d(数字)不匹配的任何[^])