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?

On Jun 13, 9:40 pm, Hypnotizing C. [email protected]
wrote:

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.

Fred

On 14 Jun, 03:20, Frederick C. [email protected] wrote:

  1. One more question. blah blah goes
    numbering and the “Answer:” segments are present accurately. From what
    Fred
    Thanks! String scanner worked like a charm.

Hi,
You can use Faster csv plugin for this.

On Jun 15, 5:09 am, Anandh K. [email protected]

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

2009/6/15 Anandh K. [email protected]

Thanks in Advance

Posted via http://www.ruby-forum.com/.


Regards,

Amit K.
Sr. Software Engrr
+91 9890654102
+91 9373087399
Blogsite: http://amitbaraik.blog.co.in/

hi amit

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

Hi there

 I m a starter in both linux and ruby on rails... is there any ruby 

gems or any other way to parse the text from open office and upload it
to the database…

Thanks in Advance

Hi everybody

   Can i use stringscanner class to parse strings of an openoffice 

document and upload it to the datbase… If so can anyone there guide me
in fixing this task… I want this task to be done in ruby on rails and
in linux platform…

Thanks in advance