How can I substitute regular expression matches and match replacements in Perl?

i.e:.

echo H#97llo | MagicPerlCommand

Stdout:

Hallo

were MagicPerlCommand something like

perl -pnle "s/#(\d+)/chr(\1)/ge"

(but this does not work).

+3
source share
2 answers

Change \1to $1in your MagicPerlCommand. The \digitbackreference style does not work when a replacement expression is evaluated (i.e. s///e).

This worked for me on Windows and Linux.

+10
source

According to the answer j_random_hackeryou should use $1, not \1.

, '/e' , Perl, . Perl, Perl , .

+4

All Articles