regex - 查找不以 "<"开头的行,执行操作

标签 regex vim sed

我正在使用 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/

相关文章:

Javascript 检查字符串是否只包含特定字符

Python findall() 起始数字和结束单词

C# 将参数命名为替换为参数值的字符串

ruby - 有没有办法在 Vim 的 'embedded' Ruby 中使用 Gems?

regex - PHP运行多实例问题

shell - 使用 awk、sed 修剪前 9 个字母

python - 如何在 Python 中使用正则表达式从 url 中提取特定模式?

vim - 在 Vim 中是否有一种本地方法可以在与相邻行交换时垂直移动文本?

vim - 运行用 python 编写的 vim 脚本?

linux - 在 GNU/Linux 中,匹配文件中的模式并使用找到的字符串提取包含另一个文件中的字符串的行