From: Eero Saynatkari Date: 2006-10-13T01:15:13+09:00 Subject: Re: scanning strings, backward? --I3tAPq1Rm2pUxvsp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2006.10.12 23:20, Rick DeNatale wrote: > 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. >=20 > 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. Ah! /m :D Granted in that case it would be simplest to use #rindex or to reverse the String altogether.=20 --I3tAPq1Rm2pUxvsp Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFFLml97Nh7RM4TrhIRAhNwAJ0SjNn7qwAf0VqR+ttBJdBDm+A4fQCdGi3j 4JDK2TnHwnppnxCouQdSHp4= =2yCJ -----END PGP SIGNATURE----- --I3tAPq1Rm2pUxvsp--