From: Sandro Paganotti Date: 2008-06-21T04:01:12+09:00 Subject: Re: Regular expressions and long text ------=_Part_13237_26195778.1213988545473 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I did not understand if you want to split the string on the full stop str.split(".") or divide the string in words and split them in two groups: str = "Ruby is great. We all know that." ([(v=str.split(" "))[0...k=((l=(v.size))/2)]]+[v[k..l]]).map{|e|e.join(" ")} => ["Ruby is great.", "We all know that."] On Fri, Jun 20, 2008 at 5:56 PM, wrote: > Hello guys, > > I've started with Ruby a month ago and I am doing some works with strings > and regular expressions. I am trying to take a long text and store the > individual sentences in an array. I can split a sentence in words and > store them in an array, but I cannot manage to do it with sentences. > > I have used the following assignment to work with the words: > > str = "Ruby is great" > words = [] > words = str.scan(/\w+/) > > The result is words[0]="Ruby" words[1]="is" and words[3]="great" > > I would like to do the following: > > str = "Ruby is great. We all know that." > > and get words[0]="Ruby is great" and ruby[1]="We all know that" > > Any ideas on how to do it with a regular expression instead of looping > through the string looking for the "."? > > Thanks, > > Guillermo > -- Go outside! The graphics are amazing! ------=_Part_13237_26195778.1213988545473--