Alexander Torstling Alexander Torstling - 1 year ago 94
Perl Question

Perl regex - match variable next to digit

I want to suffix a group match with a digit in a rexeg replace expression. How do I separate the match variable from the actal digit?

If I want

hello 55 friends -> hello 551 friend
i am 29 happy -> i am 291 happy

I tried with


But if I put a
directly after
, perl interprets it as
(rightfully so). In bash, I could have written
, but this doesn't seem to work in perl.

Answer Source

As stated in the comments, the optional curly braces for backreferences (e.g. ${1} instead of $1) does work in perl.

Demo here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download