我正在使用 vim 并有一个大文本文件,其中包含一些在 throoghout 中抛出的 html。我正在尝试为网络做准备,需要添加 <p></p>
标记到尚未格式化的行。这是我所拥有的一个例子:
Paragraph text one one line [... more ... ]
Other paragraph text on the next line [... more ... ]
<h1>html element thrown in on its own line</h1>
More paragraph text [... more ... ]
<!-- some other element (always own line) -->
There is still more text!
我正在寻找一种方法来搜索不以
<
开头的行字符,并为这些行添加开头和结尾 <p></p>
标签......这样,之后,我的文件类似于:<p>Paragraph text one one line [... more ... ] </p>
<p>Other paragraph text on the next line [... more ... ] </p>
<h1>html element thrown in on its own line</h1>
<p>More paragraph text [... more ... ] </p>
<!-- some other element (always own line ) -->
<p>There is still more text! </p>
如何找到与起始不匹配的行
<
特点?
最佳答案
^([^<].*)$
确保您的选项不允许“点匹配换行符”并替换为:
<p>$1</p>
Vim 要求您转义某些字符,但我实际上没有 vim,所以这是我对整个规则的最佳猜测:
s:^\([^<].*\)$:<p>\1</p>:g
关于regex - 查找不以 "<"开头的行,执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2266594/