Regex to parse out multiline strings
Thought I'd give credit where it was due since my previous post was answered but I have more to ask. So here is a sample of what I have after using BareGrep. I need to parse out the question, and possible answers but drop the explanations. The txt doc has about 1000 questions I've created over the years. I've removed the exact answers but I need a tool and syntax to remove the explanations. I use Mac OS 10 and Windows 7/XP.
QUESTION 19:
Why must you开发者_高级运维 blah and blah? A. So you can blah. B. So you can blah. C. So you can blah. D. So you can blah. The reason the answer is blah is blah. QUESTION 20: When should you blah blah? A. When you can blah. B. Where you can blah. C. Blah you can blah. D. All of the blah. The reason the answer is not blah is blah.
Assuming it's exactly in that format, I think you can use this regex or something similar:
"QUESTION \d+:(\n.+){5}"
These are ruby regexs.
Regex for answers:
/(^[ABCD]\..*)/
Regex for the questions:
/QUESTION [0-9]{1,2}:.*?\?/m
精彩评论