SOURCE

function log(e) {
  console.log(e)
}

function patchCount(re,s){
  re=eval("/"+re+"/ig")
  return s.match(re).length;
}

// console.log("千123百456".match(/.?[千百十个]\d+/));

// log("1234f123".match(/"^\d+f\d+"/));

let length = this.patchCount("\\d+", "千百十个234567");
log(length);



// log("==>")
// console.log(/^.*二.*?置.*$/.test('123二个位置1'));
// console.log(new RegExp("^.*二.*?置.*$").test('123二个位置1'));
const replaceCommon = {
  "=": "各",
}

const replaceCondition = {
  "^二.*?置$": "二定",
  "^三.*?置$": "三定",
  "^四.*?置$": "四定",
  "=": "各",
}

function replaceWord(regexObject, value) {
  for (let key in regexObject) {
    value = value.replace(new RegExp(key), regexObject[key]);
  }
  log(value);
  return value;
}

// // array:key-value
// // 二定-
// // 千-12345
const case1 = /^\d+[二三四]个.*?置$|^\d+[二三四]定$|^[二三四]定$/;
const case2 = /^[二三四]定/;
const caseGe = /各/;
const caseQBSG = ['千', '百', '十', '个'];

// let inputVal_ = "1234567四定=1";
let inputVal_ = "四定千123百456各20";
function analyseCondition(inputVal) {
  log("analyseCase============>");
  inputVal = replaceWord(replaceCommon, inputVal);
  let conditionArray = [];
  let condition = null;
  let money = null;
  if (caseGe.test(inputVal)) {
    let arr = inputVal.split(caseGe);
    log(arr);
    condition = arr[0];
    money = arr[1];
  } else {
    condition = inputVal;
  }

  if (case1.test(condition)) {
    if (/[二三四]/.test(condition)) {
      let match = condition.match(/[二三四]/);
      let arr = condition.split(match);
      let numbers = arr[0];
      let key = match + arr[1];
      log("key[二三四]:" + key);
      key = replaceWord(replaceCondition, key);
      conditionArray.push(key);
      conditionArray.push("全转" + numbers);
    }
  }
  if (case2.test(condition)) {
    if (/^[二三四]定.*?/.test(condition)) {
      let match = condition.match(/^[二三四]定.*?/);
      log("match:" + match);
      conditionArray.push(match[0]);
      condition = condition.replace(match[0], "");
    }
  }
  // 千百十个位置条件
  caseQBSG.forEach(function(caseQBSGVal) {
    let regexStr = "^" + caseQBSGVal + "\\d+";
    log("regexStr:" + regexStr);
    let regex = new RegExp(regexStr);
    if (regex.test(condition)) {
      let match = condition.match(regex);
      log("match:" + match);
      conditionArray.push(match[0]);
      condition = condition.replace(match[0], "");
    }
  })

  log("money============>\n" + money);
  return conditionArray;
}

// let conditionArray = analyseCondition(inputVal_);
// log("conditionArray============>\n" + JSON.stringify(conditionArray));
console 命令行工具 X clear

                    
>
console