function log(e) {
console.log(e)
}
function patchCount(re,s){
re=eval("/"+re+"/ig")
return s.match(re).length;
}
let length = this.patchCount("\\d+", "千百十个234567");
log(length);
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;
}
const case1 = /^\d+[二三四]个.*?置$|^\d+[二三四]定$|^[二三四]定$/;
const case2 = /^[二三四]定/;
const caseGe = /各/;
const caseQBSG = ['千', '百', '十', '个'];
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;
}
console