From: "Cameron, Gemma (UK)" Date: 2006-10-11T21:49:04+09:00 Subject: Re: scanning strings, backward? Just to clarify I mean using regular expressions i.e. if line =~ /$\W/i\Wdt/ Gem -----Original Message----- From: Cameron, Gemma (UK) Sent: 11 October 2006 13:10 To: ruby-talk ML Subject: Re: scanning strings, backward? Or use /$/ to look for what a line ends in? Gem -----Original Message----- From: Vidar Hokstad [mailto:vidar@edgeio.com] Sent: 11 October 2006 12:35 To: ruby-talk ML Subject: Re: scanning strings, backward? *** WARNING *** This mail has originated outside your organization, either from an external partner or the Global Internet. Keep this in mind if you answer this message. Bil Kleb wrote: > So, the tasks are roughly, > > 1) Goto line 1707 of the file > 2) Search backward until line.match /\Wdt\W/i > 3) Remove /dt/i > > I'm stuck on an elegant, i.e., Ruby, way to do the first two steps. > Please point me toward the glittering light. For 1) Assuming the lines aren't fixed length: Read in the entire file into an array (using IO#readlines), in which case you can skip straight to the line you want, or counting line by line until you find the one you want. For 2) Any particular reason why you need to search backwards? My suggestion would be to look at String#gsub - that will help you handle both 2) and 3) in one go. Vidar ******************************************************************** This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person. ********************************************************************