我想用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