in reply to Re^2: Problems with matching?
in thread Problems with matching?
if you just want to replace the first occurance of a name, then use the following
my %new_names; $file =~ s{^\s+description\s\K(\w\w\w\w)(?=-\w+-\w+;)}{ my $name = $1; if (!$new_names{$name}) { $name = $new_names{$name} = my_rand(); } $name }gme;
Or if you want to replace all occurances of a name with the new name, then the following would work:
my %new_names; $file =~ s{^\s+description\s\K(\w\w\w\w)(?=-\w+-\w+;)}{ $new_names{$1} //= my_rand(); }gme;
Note: since the suffix appears to not be relevant, I added it to the positive look ahead assertion.
|
|---|