If you're really committed to the regexp, this works:
my $u = 'http://adserver.adtech.de/?addyn|2.0|323|91793|1|277|target=_ +blank'; print "$u\n"; $u =~ s/(.*\|.*\|.*\|.*\|.*\|).*(\|.*)/${1}976$2/; print "$u\n"; __END__ http://adserver.adtech.de/?addyn|2.0|323|91793|1|277|target=_blank http://adserver.adtech.de/?addyn|2.0|323|91793|1|976|target=_blank
You might also try using split and join:
my $u = 'http://adserver.adtech.de/?addyn|2.0|323|91793|1|277|target=_ +blank'; print "$u\n"; my @fields = split /\|/, $u; $fields[5] = 976; $u = join '|', @fields; print "$u\n"; __END__ http://adserver.adtech.de/?addyn|2.0|323|91793|1|277|target=_blank http://adserver.adtech.de/?addyn|2.0|323|91793|1|976|target=_blank
I also think it would be good to have a more specific expression. For example, instead of ".*", use "\d+" to make sure it's not an empty field and to make sure that it really does have digits and not some other junk you weren't expecting.
In reply to Re: Replace part of a regex match
by kyle
in thread Replace part of a regex match
by krisravn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |