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.
我正在尝试编写不同的 sed 脚本来美化 ruby 代码。我试图解决的一种情况a=>b是a=> b用a => b. 匹配此条件的正则表达式是,[^ ]=>但它也匹配之前的 1 个字符=>。所以,当我尝试替换它时,并没有给我想要的结果s/[^ ]=>/ =>/g
a=>b
a=> b
a => b
[^ ]=>
=>
s/[^ ]=>/ =>/g
有什么建议么?
您需要使用捕获:
s/\([^ ]\)=>/\1 =>/g
无条件更换双方如何?
s/ ?=> ?/ => /g