Perl, add a character to the ith capture group

I have one liner:

perl -pe 's|.*?((\d{1,3}\.){3})xxx.*|\1|' 

I pass this command with some input, for example 192.168.1.xxx , and it works. Now I want to add 0 to the output sequence, but of course, if I just add 0 immediately after \1 , it will be analyzed as the tenth capture group. How can I associate it with the \1 directive?

+6
source share
1 answer

You should use $1 instead of \1 in permutations . Then you can use curly braces to write it unambiguously as follows:

 perl -pe 's|.*?((\d{1,3}\.){3})xxx.*|${1}0|' 
+11
source

Source: https://habr.com/ru/post/908098/


All Articles