This seems to handle the pathological cases?
#! perl -lsw use strict; my @reps = map{ sprintf '%05d', $_ } 0 .. 20; while(<DATA>) { my $n=0; # redundant /e option removed # per [Abigail-II]'s comment below. s/\d{5}/$reps[$n++]/g; print; } __DATA__ 0000000000000000000000000000000000000000000000000000000000000000000000 +0000000000000000 00000xxxx00000xxxxx00000xxxx00000xxxxx00000xxx00000xxx00000xx00000xxx0 +0000x00000x00000
Outputs
c:\test>234342 0000000001000020000300004000050000600007000080000900010000110001200013 +0001400015000160 00000xxxx00001xxxxx00002xxxx00003xxxxx00004xxx00005xxx00006xx00007xxx0 +0008x00009x00010
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
In reply to Re: repeated replacement regex
by BrowserUk
in thread repeated replacement regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |