2015-10-06 92 views
0

我正在使用正则表达式来查找答案的选择和他们的描述。 到现在为止工作很好,但问题是,我不知道如何包括多个行描述,而不包括下一个选择。需要帮助正则表达式

我现在的正则表达式:

^(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) 

Demo on regex101

我需要两个随机文本的句子后,也包含在选择B匹配选择B,但不包括选项C.

回答

1

您可以尝试:

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

Demo on regex101

说明

  • (?!Choice):字符串不与 “选择”

  • [^\n]开始:任何字母,除 “\ n”

+0

工作就像魅力!在其他类似的情况下也使用这个原则。谢谢! –