There\'s a file dummy.txt
The contents are:
9/0/2010
9/2/2010
10/11/2010
I have to change the month portion (0,2,11) to +1, ie, (1,3
Three changes:
e
modifier
to allow an expression in the
replacement part.g
modifier. This is not needed if you've one date per line.$1
on the replacement side, not a backreferenceThis should work:
$line =~ s{/(\d+)/}{'/'.($1+1).'/'}eg;
Also if your regex contains the delimiter you're using(/
in your case), it's better to choose a different delimiter ({}
above), this way you don't have to escape the delimiter in the regex making your regex clean.