繁体   English   中英

需要正则表达式的帮助

[英]Need help for regex

我正在使用正则表达式来寻找答案选择及其描述。 到目前为止,它工作得很好,但是问题在于,如果不包括next Choice,我无法弄清楚如何包括多行描述。

我当前的正则表达式:

^(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”外的任何字母

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM