2015-10-06 116 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

工作就像魅力!在其他類似的情況下也使用這個原則。謝謝! –