我使用的是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!
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来搜索不以<字符开头的行,对于这些行,添加开始和结束<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>
Run Code Online (Sandbox Code Playgroud)
如何查找与起始字符不匹配的行<?
Joh*_*zen 11
^([^<].*)$
Run Code Online (Sandbox Code Playgroud)
确保您的选项不允许"点匹配换行符"并替换为:
<p>$1</p>
Run Code Online (Sandbox Code Playgroud)
Vim要求你逃避某些角色,但我没有vim,所以这是我对整个规则的最佳猜测:
s:^\([^<].*\)$:<p>\1</p>:g
Run Code Online (Sandbox Code Playgroud)