R-J
R-J

Reputation: 936

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.

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

I need the two random text sentences after Choice B to be also included in Choice B match, but without including Choice C.

Upvotes: 0

Views: 61

Answers (1)

Jose Ricardo Bustos M.
Jose Ricardo Bustos M.

Reputation: 8174

You can try:

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

Demo on regex101

Explanation

  • (?!Choice): String don't beginning with "Choice"

  • [^\n]: any letter, except "\n"

Upvotes: 1

Related Questions