Commit adea255320863a8a1d8987f4020a449815dd3de3

Authored by 刘有才luck
1 parent 805479e7

feat: 正则修改

src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue
@@ -553,10 +553,21 @@ export default { @@ -553,10 +553,21 @@ export default {
553 // 正则表达式: 553 // 正则表达式:
554 const regexs = [/[0-9]+[.)]/, /(\d+分)/, /^(\d{1,3})/]; 554 const regexs = [/[0-9]+[.)]/, /(\d+分)/, /^(\d{1,3})/];
555 555
556 - regexs.forEach((regex) => {  
557 - input = input.replace(regex, "");  
558 - });  
559 - // 如果没有匹配,直接返回原字符串 556 + // 使用正则表达式匹配并处理输入字符串
  557 + for (const regex of regexs) {
  558 + const match = input.match(regex);
  559 + if (match) {
  560 + if (regex === regexs[2]) {
  561 + // 如果匹配第三条规则,使用substring截取返回结果的长度加1
  562 + const matchLength = match[0].length;
  563 + return input.substring(matchLength + 1).trim();
  564 + } else {
  565 + // 如果匹配第一条或第二条规则,替换匹配的部分
  566 + input = input.replace(regex, "");
  567 + }
  568 + }
  569 + }
  570 +
560 return input; 571 return input;
561 }, 572 },
562 573
src/views/basic/askTestQuestion/wrongQuestion.vue
@@ -592,13 +592,24 @@ export default { @@ -592,13 +592,24 @@ export default {
592 this.getClassList(); 592 this.getClassList();
593 }, 593 },
594 processString(input) { 594 processString(input) {
595 - // 正则表达式 595 + // 正则表达式
596 const regexs = [/[0-9]+[.)]/, /(\d+分)/, /^(\d{1,3})/]; 596 const regexs = [/[0-9]+[.)]/, /(\d+分)/, /^(\d{1,3})/];
597 597
598 - regexs.forEach((regex) => {  
599 - input = input.replace(regex, "");  
600 - });  
601 - // 如果没有匹配,直接返回原字符串 598 + // 使用正则表达式匹配并处理输入字符串
  599 + for (const regex of regexs) {
  600 + const match = input.match(regex);
  601 + if (match) {
  602 + if (regex === regexs[2]) {
  603 + // 如果匹配第三条规则,使用substring截取返回结果的长度加1
  604 + const matchLength = match[0].length;
  605 + return input.substring(matchLength + 1).trim();
  606 + } else {
  607 + // 如果匹配第一条或第二条规则,替换匹配的部分
  608 + input = input.replace(regex, "");
  609 + }
  610 + }
  611 + }
  612 +
602 return input; 613 return input;
603 }, 614 },
604 615