正则表达式:在 html 编辑器中插入换行符

发布于 2024-12-28 12:51:01 字数 167 浏览 1 评论 0原文

如果我的编辑器中有一些像这样的 html:

<p>Some code here.</p></This needs to be on a new line!>

如何在实际编辑器(而不是输出)中获取新行上的最后一个标签?

If I have some html in my editor like this:

<p>Some code here.</p></This needs to be on a new line!>

How do I get the last tag on a new line in the actual editor (not the output)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别挽留 2025-01-04 12:51:01

如果要将最后一个结束标记放在新行上:

模式:

(</[a-zA-Z]+>)$

替换模式:

\r\n\1

更新:

完全匹配:

(</This needs to be on a new line!>)$

If you want to put the last closing tag on a new line:

Pattern:

(</[a-zA-Z]+>)$

Replace Pattern:

\r\n\1

Update:

Exact match:

(</This needs to be on a new line!>)$
纵情客 2025-01-04 12:51:01

尝试这样的事情:

 sed -i 's|\(.*p>\)\(</This.*\)|\1\n\2|g' <your files>

s         // substitute
|         // begin search
\(        // begin group 1
.*p>      // search greedy until 'p>' found
\)        // end group 1
\(        // begin group 2
</This.*  // search for '</This' then be greedy until the end 
\)        // end group 2
|         // begin replace
\1        // insert group 1
\n        // insert new line character '\n'
\2        // insert group 2
|         // end replace
g         // global replace for substitute

Try something like that:

 sed -i 's|\(.*p>\)\(</This.*\)|\1\n\2|g' <your files>

s         // substitute
|         // begin search
\(        // begin group 1
.*p>      // search greedy until 'p>' found
\)        // end group 1
\(        // begin group 2
</This.*  // search for '</This' then be greedy until the end 
\)        // end group 2
|         // begin replace
\1        // insert group 1
\n        // insert new line character '\n'
\2        // insert group 2
|         // end replace
g         // global replace for substitute
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文