简体   繁体   English

需要正则表达式的帮助

[英]Need help for regex

I'm using regex to look for answer choices and their descriptions. 我正在使用正则表达式来寻找答案选择及其描述。 Until now it's working great, but the problem is that I can't figure out how to include multiple line description without including next Choice. 到目前为止,它工作得很好,但是问题在于,如果不包括next Choice,我无法弄清楚如何包括多行描述。

My current regex: 我当前的正则表达式:

^(Choice [A-I] \(.*\) +(?:is incorrect. )?($|\r?.*))

Test cases: 测试用例:

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 regex101上的演示

I need the two random text sentences after Choice B to be also included in Choice B match, but without including Choice C. 我需要选择B之后的两个随机文本句子也包含在选择B匹配中,但不包括选择C。

You can try: 你可以试试:

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

Demo on regex101 regex101上的演示

Explanation 说明

  • (?!Choice) : String don't beginning with "Choice" (?!Choice) :字符串不以“ Choice”开头

  • [^\\n] : any letter, except "\\n" [^\\n] :除“ \\ n”外的任何字母

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

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