In a perl regex, is there an updating match counter which I can use as a prefix in the replace text? For example, I want to replace each occurrence of position with position 1, position 2 and so on.
No, there is no predefined counter, but you can easily create one yourself:
my $i = 1;
s/position/ "position " . $i++ /eg;
(Using the /e flag to tell perl to parse the replacement part as a block of code, not a string.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With