From: Jason Mayer Date: 2006-12-13T02:43:27+09:00 Subject: Re: Newbie questions ------=_Part_74192_5184740.1165945405368 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 12/12/06, Dav Jones wrote: > > Thanks. I've got it reading in a file and checking each line against a > regular expression. > > How would I go about taking individual sections of a line? > i.e. if the word 'example:' appears on a line then it takes that and a > few characters before or after it (it will be something specific its > just the question is in general here) so for > blah blah blah example: twenty blah blah > it returns me 'example: twenty' > > -- > Posted via http://www.ruby-forum.com/. > > Complete nuby here, but I'll give it a shot: example = "blah blah example: twenty." re = /example: .+[^ \t\n\r\f]/ stuff = re.match(example) puts stuff Output: C:\ruby\programs>ruby regex2.rb example: twenty. ------=_Part_74192_5184740.1165945405368--