英文:
How to change HTML tags preserving its contained content
问题
在多个HTML文件中,我有217个实例:
<p class="quote">“许多不同的引用。”</p>
我想要批量将它们更改为:
<blockquote>
<p>“许多不同的引用。”</p>
</blockquote>
我曾考虑使用正则表达式,直到我看到了这个答案,它不鼓励使用正则表达式。但这个答案相当古老,所以我想知道是否有新的最佳方法。
我尝试过正则表达式,但不确定是否是最有效的方法。我正在使用vscodium,但没有立即找到相关的扩展。
英文:
Across multiple html files I have 217 instances of:
<p class="quote">“Lots of different quotes.”</p>
And want to bulk change them into:
<blockquote>
<p>“Lots of different quotes.”</p>
</blockquote>
I was thinking of using regular expressions, until I came across this answer, which discourages the use of regex. But the answer is quite old so I wonder if there is a new best approach.
I tried regex but I am not sure whether that is the most efficient method. I am using vscodium, but didn't immediately find relevant extensions.
答案1
得分: 0
使用VSCodium,以下正则表达式可以捕获大多数情况并进行替换:
<p class="quote">([^<]+)</p>
或者使用以下正则表达式以包括嵌套标签:
<p class="quote">((?:[^<]+|<(?!/p>))*)</p>
替换为:
<blockquote>\n\t\t\t<p>$1</p>\n\t\t</blockquote>
英文:
Using VSCodium the following regular expression captured most cases by replacing:
<p class="quote">([^<]+)</p>
or the following to include nested tags
<p class="quote">((?:[^<]+|<(?!/p>))*)</p>
with
<blockquote>\n\t\t\t<p>$1</p>\n\t\t</blockquote>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论