我有一个这样的文字文件:
1 textA == this is textA ==
1.1 textB === this is textB ===
2 textC == this is textC ==
2.1 textD === this is textD ===
2.1.1 textE ==== this is textE ====
什么是正确的正则表达式模式来格式化上面的文本:
== this is textA ==
=== this is textB ===
== this is textC ==
=== this is textD ===
我已经尝试在vim中执行此操作:
^\w* -> this pattern just changes only textA and textB
我需要检测“。”和任何字符或单词,直到符合“=”符号。 “=”符号后面的任何字符都将被删除。提前感谢您的任何答案和指示。
<小时/> 的解决方案
^.\{-}\ze=
说明:
^. -> started with any single character
\{-} -> matches 0 or more of the preceding atom, as few as possible
\ze= -> Matches at any position, and sets the end of the match there: The previous char is the last char of the whole match
用人的话来说:
“查找并替换以任何单个字符开头的文本,后跟任何内容,并以”=“符号结束。
答案 0 :(得分:4)
:%s/^.\{-}\ze=//
有关如何在Vim中设计reg.exps的更多详细信息,请参阅:help pattern
这是Vim IMHO中最有用的部分帮助。
:help :g
和:help :v
也可能对您感兴趣。例如,您可以这样做:
:g/=/normal! 0dt=
将模拟您在包含=符号的每一行上键入0dt =。