SOURCE

var str = '123456'
var reg = /(1(2)3)(4(5)6)/

let result = str.replace(reg, function ($0, $1, $2, $3, $4, $5, $6) {
  console.log($0, $1, $2, $3, $4, $5, $6)
  return $1
})

console.log('结果:' + str.replace(reg, '$1'))

console 命令行工具 X clear

                    
>
console