Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想增加字符串 perl 中所有数字的出现,例如。如果我的字符串为 $str = "转到第 34 页并阅读第 3 行",则应将其更改为 $str = "转到第 35 页并阅读第 4 行"。
我尝试使用
$str =~ s/[\d]/$&+1/g
但它以字符串形式输出,即“转到第 34+1 页并阅读第 3+1 行”
这个怎么样:
$ echo "foo 1 bar 2" | perl -pE 's/(\d+)/$1+1/ge' foo 2 bar 3
关键是e将替换部分视为表达式的正则表达式选项。
e