我正在使用正则表达式来查找答案选项及其描述。 到目前为止,它工作得很好,但问题是我无法弄清楚如何在不包含下一个选择的情况下包含多行描述。
我当前的正则表达式:
^(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)
我需要选项 B 后面的两个随机文本句子也包含在选项 B 匹配中,但不包含选项 C。
最佳答案
你可以尝试:
(Choice [A-I] \(.*\) )(((?!Choice)[^\n]+[\n]?)+)?
说明
(?!Choice)
:字符串不以“Choice”开头[^\n]
:除“\n”之外的任何字母
关于javascript - 需要正则表达式帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32980947/