I need to Parse Values out of a Text that looks like this:
Description. Question?
A. First Answer
B. Second Answer
C. Third Answer
Answer: A, B
Now i need to find out the Description, the Question, the Answers and which Answers are correct. Is that Possible with RegEx? I know it should be possible, but I’m not an RegEx Expert.
Seriously Regex is great, but once the parsing logic becomes advanced, so does the regex needed to solve the problem. I would suggest breaking up the logic into smaller pieces (i take it you have some sort of scripting language available to do some preprocessing?)
Even if you get the whole thing matched with one killer regex – changing it later (by you or some other sorry person) would be a pain.
I would match the answers with something like this (You’d need to strip the commas):
And then I’d do logic to reparse the text with the answers found with the first regex, with something like this (rebuilding the match, in this case A was an answer):
It might not be something to flash your friends with, but it will be easier to maintain, and a heck lot easier to understand.