<p class="mb-40px">Decisive too, of
<p class="mb-40px">otherwise, it was the opportunity to
<p class="mb-40px">acquire what were to be two pillars
<p class="mb-40px">fundamentals of his intellectual formation:
<p class="mb-40px">Latin and virtually none of the Greek
<p class="mb-40px">written down, they were the subject of daily commentary on Apollo.</p>
必须成为:
<p class="mb-40px">Decisive too, of otherwise, it was the opportunity to acquire what were to be two pillars fundamentals of his intellectual formation: Latin and virtually none of the Greek written down, they were the subject of daily commentary on Apollo.</p>
我的正则表达式不是很好:
寻找: (<p class="mb-40px">)(.*?\s+\n)[\s\S]*?</p>
替换为: \1$0\3
您可以简单地搜索(使用正则表达式):
并替换为(注意后面的空格
\1
和一个空格。这将找到所有
<p class="mb-40px">
标签(不在另一个标签之后,所以不是第一个。)([^>])\s+(<p class="mb-40px">)
\1\x20
. matches newline
正则表达式不能连接可变数量的行,这比正则表达式更适合编程语言。
我的解决方案需要一次连接两行,因此您需要根据需要多次执行“全部替换”,直到替换失败。
这是复杂的搜索字符串:
查找内容:
^<p class="mb-40px">(.*(?<!p>))\R^<p class="mb-40px">(.*?(?<!p>))$
替换为:
<p class="mb-40px">\1 \2
搜索模式:不带“.匹配换行符”的正则表达式。
要了解其工作原理,请参阅regex101中的术语分解 。
参考: 不以给定后缀结尾的字符串的正则表达式。