From: Rick DeNatale Date: 2006-10-12T23:20:51+09:00 Subject: Re: scanning strings, backward? On 10/11/06, Eero Saynatkari wrote: > On 2006.10.11 20:05, Bil Kleb wrote: > > Hi, > > > > I would like to automate a code cleanup task which involves > > finding warning messages like, > > > > Warning: ../../LibF90/bc_inviscid.f90, line 1707: > > DT explicitly imported into BC_INVISCID_FLUX but not used > > detected at BC_INVISCID_FLUX@ > > > > and removing the offending unused import. > > > > So, the tasks are roughly, > > > > 1) Goto line 1707 of the file > > File.readlines for reasonably sized files, f.each_with_index > for skipping over until 1707. > > > 2) Search backward until line.match /\Wdt\W/i > > 3) Remove /dt/i > > Combine these by anchoring. > > line.sub /(.*\W)dt(\W.*)$/i, '\1\2' > > If the \W are spaces, strip one of them out. I believe that the OP doesn't want to search line 1707 backwards for dt, he want's to search the file backwards starting at line 1707 (or maybe 1706) for a line containing dt. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/