diff --git a/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue b/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue index 0c06918..c5f5a83 100644 --- a/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue +++ b/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue @@ -553,10 +553,21 @@ export default { // 正则表达式: const regexs = [/[0-9]+[.)]/, /(\d+分)/, /^(\d{1,3})/]; - regexs.forEach((regex) => { - input = input.replace(regex, ""); - }); - // 如果没有匹配,直接返回原字符串 + // 使用正则表达式匹配并处理输入字符串 + for (const regex of regexs) { + const match = input.match(regex); + if (match) { + if (regex === regexs[2]) { + // 如果匹配第三条规则,使用substring截取返回结果的长度加1 + const matchLength = match[0].length; + return input.substring(matchLength + 1).trim(); + } else { + // 如果匹配第一条或第二条规则,替换匹配的部分 + input = input.replace(regex, ""); + } + } + } + return input; }, diff --git a/src/views/basic/askTestQuestion/wrongQuestion.vue b/src/views/basic/askTestQuestion/wrongQuestion.vue index eacdcf3..4d5fdbb 100644 --- a/src/views/basic/askTestQuestion/wrongQuestion.vue +++ b/src/views/basic/askTestQuestion/wrongQuestion.vue @@ -592,13 +592,24 @@ export default { this.getClassList(); }, processString(input) { - // 正则表达式 + // 正则表达式: const regexs = [/[0-9]+[.)]/, /(\d+分)/, /^(\d{1,3})/]; - regexs.forEach((regex) => { - input = input.replace(regex, ""); - }); - // 如果没有匹配,直接返回原字符串 + // 使用正则表达式匹配并处理输入字符串 + for (const regex of regexs) { + const match = input.match(regex); + if (match) { + if (regex === regexs[2]) { + // 如果匹配第三条规则,使用substring截取返回结果的长度加1 + const matchLength = match[0].length; + return input.substring(matchLength + 1).trim(); + } else { + // 如果匹配第一条或第二条规则,替换匹配的部分 + input = input.replace(regex, ""); + } + } + } + return input; },