需要帮助的正则表达式

Need help for regex

本文关键字:正则表达式 帮助      更新时间:2023-09-26

我使用正则表达式来查找答案选择及其描述。到目前为止,它工作得很好,但问题是我不知道如何在不包括下一个选择的情况下包括多行描述。

我当前的正则表达式:

^(Choice [A-I] '(.*') +(?:is incorrect. )?($|'r?.*))
测试用例:

Choice B (Predominance of eosinophils) zfdfdfbhdfdfdf
fgdfgdfgdfdfdfhd fgdfgdfgdsgsf
sgsgdfgdf gdfgdfgdfgdfgd gdfg
Choice C (Monosodium urate crystals) fghfdghfghfghfh
Choice D (Spirochetes) is incorrect fghfghfghfghfghf
Choice E (Predominance of polymorphonuclear cells) 

regex101的演示

我需要选项B之后的两个随机文本句子也包含在选项B匹配中,但不包括选项c。

您可以尝试:

(Choice [A-I] '(.*') )(((?!Choice)[^'n]+['n]?)+)?

regex101的演示

  • (?!Choice):字符串不以"Choice"开头

  • [^'n]:除"'n"外的任意字母