in reply to A text replacement question
UPDATE: Integrated holli's fix and animator's regex code from below. (untested!)#use strict; #use warnings; my ($dirname, $file, %words); opendir(DIR, ".") or die "can't opendir $dirname: $!"; while (defined($file = readdir(DIR))) { if ($file =~ /\.html?/) { open my $F, $file or die "Could not open $file\n"; while (<$F>) { #do stuff s/ (?<= # Look back-group weak # Match the word weak <INPUT TYPE=radio NAME= # tag ( # Capuring group: $1 / \1 \w{2}\d\w{2} # ) # End-capture VALUE=\d> # tag (?: # Non capturing group <INPUT TYPE=radio NAME= # tag \1 # It's possible that this should be $ +1, as I said, the code is untested. VALUE=\d> ){6} # There are 7 input tags, one already + matches, so 6 to go. ) # End look-back (?= # Look-ahead-group strong ) # End look-ahead / the text you want to insert /ixg; } close $F; } } closedir(DIR);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A text replacement question
by holli (Abbot) on Feb 15, 2005 at 14:05 UTC |