相关文章推荐
含蓄的汽水  ·  Maven Central: ...·  昨天    · 
俊逸的斑马  ·  Struggling migrating ...·  昨天    · 
淡定的鸡蛋  ·  Replacing nashorn ...·  昨天    · 
呐喊的罐头  ·  typescript ...·  1 年前    · 
逆袭的创口贴  ·  stream filter ...·  2 年前    · 
满身肌肉的海豚  ·  Android ...·  2 年前    · 

js replace $1 $2

"replace" 函数是 JavaScript 中常用的字符串操作函数,它可以替换字符串中的特定内容。如果使用了 " 1 " " 1" 和 " 2",那么它们代表的是在字符串替换时被匹配到的第一个和第二个组(group)。

let str = "hello world";
let newStr = str.replace(/world/, "$1 $2");
console.log(newStr);
// 输出: hello $1 $2

希望这对您有所帮助。

  •