Perl regex replace numbers with themselves, just one higher

numbers, perl, regex

Solution

Use `s///e` - evaluation modifier and you can put arbitrary perl codes in second part.

$x = "hello 3";
$x =~ s/([0-9]+)/$1 + 1/eg;
print $x;

// hello 4

ref: http://perldoc.perl.org/perlretut.html#Search-and-replace

Problem

I have a text, how can I replace all numbers in it with themselves just one higher? I've tried things like the following: ``` $buffer_content=~s/(\d)/($1++)/g; ```

Original source