My idea is still rather stupid, if the big guy has a better idea, can exchange in the comments section

  • The relations on the regulars can continue to be decoupled, writing the regulars as passed parameters if necessary
exports.repStr = function (str) {
  const s = str.replace(/[a-z]|[A-Z]|[\u4e00-\u9fa5]|[0-9]|\s/g."")
  let pattern = '/'
  const noStr = new Set(s)
  for (const item of noStr) {
    pattern = `${pattern}\ \${item}| `
  }
  pattern += "\\s/g"
  pattern = eval(pattern)
  return str.replace(pattern, "")}Copy the code

The Set constructor is used to de-duplicate strings other than those specified