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