Parsing text in a rails application

I have a piece of text which is in the following format:
"1. Question blah blah blah. goes on blah blah
blah blah.
Answer: Answer blah, blah goes on like
this blah blah.
2. One more question. blah blah goes
on like this again.
Answer: Again and again, over and over."

Now taking a piece of text, I have to break it down to pairs of
question and answer sets so that they can be saved in to question
model - which has a question and answer attribute. A single piece of
text saved in a Post model needs to be parsed into a number of
question models.
The problem is that the text is very idiosyncratic, with numerous line
breaks and carriage returns inside each question and answer but the
numbering and the "Answer:" segments are present accurately. From what
I read through various sources, this can be accomplished through
regular expressions but I am not able to figure out how to go about
this. Could someone explain how this can be accomplished for this
particular case?

you may find string scanner more appropriate in this case. In a
nutshell you tell it to scan until it finds text matching a particular
pattern (in your case the beginning of question and beginning of
answer markers), and it tells you all the text it consumed in between.


Thanks! String scanner worked like a charm.

youc an use Faster Csv plugin for this. It’s very easy by this plugin.

    You can use Faster csv plugin for this.

hi amit

   Thanks for your reply... can i use string scanner class to accomplish
the task...