- 增加对 'A:内容,B:内容,C:内容' 格式的支持 - 使用正则 /[A-Da-d](?=[::])/g 提取所有选项字母
This commit is contained in:
@@ -355,12 +355,12 @@ const transformDifyQuestions = (difyQuestions: any[]): any[] => {
|
||||
correctLetters = correctAnswerStr.match(/[A-Da-d]/g)?.map(l => l.toUpperCase()) || []
|
||||
console.log(` ✓ 匹配情况1(纯字母): correctLetters=[${correctLetters.join(',')}]`)
|
||||
} else {
|
||||
// 情况2:选项字母+内容格式(如 "A:xxx" 或 "A: xxx" 或 "A:xxx")
|
||||
// 支持多种冒号格式:中文全角冒号、英文冒号
|
||||
const prefixMatch = correctAnswerStr.match(/^([A-Da-d](?:[,、\s]*[A-Da-d])*)\s*[::]\s*/)
|
||||
if (prefixMatch) {
|
||||
correctLetters = prefixMatch[1].match(/[A-Da-d]/g)?.map(l => l.toUpperCase()) || []
|
||||
console.log(` ✓ 匹配情况2(字母+冒号): prefixMatch="${prefixMatch[0]}", correctLetters=[${correctLetters.join(',')}]`)
|
||||
// 情况2:多选项带内容格式(如 "A:分组列,B:聚合函数,C:常量")
|
||||
// 匹配所有 "X:" 或 "X:" 格式,提取字母
|
||||
const multiOptionMatch = correctAnswerStr.match(/[A-Da-d](?=[::])/g)
|
||||
if (multiOptionMatch && multiOptionMatch.length > 0) {
|
||||
correctLetters = multiOptionMatch.map(l => l.toUpperCase())
|
||||
console.log(` ✓ 匹配情况2(多选项带内容): correctLetters=[${correctLetters.join(',')}]`)
|
||||
} else {
|
||||
// 情况3:只有开头字母(如 "A" 后面直接跟非字母内容)
|
||||
const firstLetterMatch = correctAnswerStr.match(/^([A-Da-d])(?![A-Za-z])/)
|
||||
|
||||
Reference in New Issue
Block a user