From: Robert Klemme Date: 2013-07-10T06:02:28+09:00 Subject: Re: search a string with ruby then read what comes after the string in the same line --001a11c361080daaeb04e11a785a Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jul 9, 2013 at 7:44 PM, dJD col wrote: > I am trying to look for a a given string in a text and once i find the > string > I want to be able to store a string that comes after it. > > For example I would look for a String "JUNE" and once I find "JUNE" in > the text > I want to store the string that follows JUNE in a variable x. This > string should be 7 characters. So if the text has "JUNE seventh 2012". I > want to be able to store the string seventh in a variable x. Such that > puts x will print seventh on the screen. > > This is what I have so far but this only prints the string that I am > looking for. I would like to be able to print the string that comes > after the string I am looking for. > > file_names = ['Document.txt'] > > file_names.each do |file_name| > text = File.read(file_name) > > x = text.scan("June") > puts x > > end > > please advise. > You need a regular expression with a capturing group. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --001a11c361080daaeb04e11a785a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Cheers
--001a11c361080daaeb04e11a785a--