From: Vidar Hokstad Date: 2006-10-11T20:35:12+09:00 Subject: Re: scanning strings, backward? 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