我想用sed替換一個模式。我想進行全局搜索並替換 ,其中我將~~\d{3}~~
替換爲A\d{3}\B
。換句話說,我想 替換~~345~~
與A345B
。正則表達式 - 替換使用反向引用
我的文件(src.txt)包含一個行:
hello ~~123~~ hello ~~12~~ hello ~~456~~ hello
我想這個更改爲:
hello A123B hello ~~12~~ hello A456B hello
我想這在命令行上:
sed -i -c "s/~~(\d{3})~~/A\\1B/g" src.txt
然而,沒有什麼改變。我究竟做錯了什麼?
P.S. - 最終我想在Javascript中做這種替換 。
謝謝!
非常感謝您! regex101.com上的工具非常有幫助。 – CurtisD 2014-09-29 20:18:47