問題
次のような行でいっぱいのファイルがあります
convert.these.dots.to.forward.slashes/but.leave.these.alone/i.mean.it
取得したものを検索して置換したい
convert/these/dots/to/forward/slashes/but.leave.these.alone/i.mean.it
。最初のスラッシュまで / に変換されます
質問
問題を解決するために正規表現の検索と置換を作成するにはどうすればよいですか?
試みられた解決策
perlで後読みしてみましたが、可変長の後読みが実装されていません
$ echo "convert.these.dots.to.forward.slashes/but.leave.these.alone/i.mean.it" | perl -pe 's/(?<=[^\/]*)\./\//g'
Variable length lookbehind not implemented in regex m/(?<=[^/]*)\./ at -e line 1.
回避策
可変長の先読みが実装されているため、この汚いトリックを使用できます
$ echo "convert.these.dots.to.forward.slashes/but.leave.these.alone/i.mean.it" | rev | perl -pe 's/\.(?=[^\/]*$)/\//g' | rev
convert/these/dots/to/forward/slashes/but.leave.these.alone/i.mean.it
この問題に対するより直接的な解決策はありますか?