On Tue, 1 Mar 2011 19:31:36 +0900, Shadowfirebird wrote:
>> i want to get all the possible question from that paragraph
>
> Do you mean that you want to extract all the sentences that end in a
> question mark?
>
> Untested (so don't laugh, all you Ruby grownups):
>
> def questions(para)
>     ans = []
>     para.split(/[\.\?\!] /).each do |sn|
>         ans << sn if sn ~= /\? $/
>     end
>
>     return ans
> end
>
> (That won't cope with brackets.)  Said the Vicar: "Or quotes."   But
> it's a starting point -- assuming that that was what you meant.
>
> Presumably someone smarter than me could do better with a single 
> regex.

 def questions(para)
   para.scan(/([^!.]+?\?|.+?[!.])\w*/m).flatten.select { |m| m[-1] == ?? 
 }.map &:strip
 end

 ruby-1.9.2-p136 :063 > str
  => "This is a sentence? Yes. And this too? Definitely!\n"
 ruby-1.9.2-p136 :064 > questions(str)
  => ["This is a sentence?", "And this too?"]

-- 
   WBR, Peter Zotov.