Reputation: 2045
I want to add a string (A
) after all specific other strings (bbc
). So, I match bbc
and want to replace it with itself with A
appended ('aabbcc' => 'aabbcAc'
).
Is there a replacement back-reference that gets substituted with the whole match?
$0
doesn't seem to work – its content is always "-e", for some reason:
$ echo 'aabbcc' | perl -p -e 's/bbc/$0A/g'
aa-eAc
Upvotes: 2
Views: 398
Reputation: 91385
Use $&
, see https://perldoc.perl.org/perlvar#$&
$ echo 'aabbcc' | perl -p -e 's/bbc/$&A/g'
aabbcAc
Upvotes: 5