【问题标题】:How to add a text in every line with an existing texts using regex in Notepad++?如何在 Notepad++ 中使用正则表达式在每一行中添加现有文本的文本?
【发布时间】:2020-07-03 12:04:22
【问题描述】:

是否可以在 Notepad++ 中的每一行之后添加文本或 HTML 标记?

例如,这段文字:

                    <p class="text-center mb-0 cfont"><a class="cfont" href="#tag">[COMPANY]</a></p>
                    Alexander Hamilton (Alexander Hamilton)
                    We are waiting in the wings for you (waiting in the wings for you)
                    You could never back down
                    You never learned to take your time!
                    Oh, Alexander Hamilton (Alexander Hamilton)
                    When America sings for you
                    Will they know what you overcame?
                    Will they know you rewrote the game?
                    The world will never be the same, oh

                    <p class="text-center mb-0 cfont"><a class="cfont" href="#tag">[BURR, MEN, & COMPANY]</a></p>
                    The ship is in the harbor now
                    See if you can spot him
                    Just you wait
                    Another immigrant
                    Comin’ up from the bottom
                    Just you wait
                    His enemies destroyed his rep
                    America forgot him

目标是让上面的文字变成这样:(添加break标签)

                    <p class="text-center mb-0 cfont"><a class="cfont" href="#tag">[COMPANY]</a></p>
                    Alexander Hamilton (Alexander Hamilton)</br>
                    We are waiting in the wings for you (waiting in the wings for you)</br>
                    You could never back down</br>
                    You never learned to take your time!</br>
                    Oh, Alexander Hamilton (Alexander Hamilton)</br>
                    When America sings for you</br>
                    Will they know what you overcame?</br>
                    Will they know you rewrote the game?</br>
                    The world will never be the same, oh</br>

                    <p class="text-center mb-0 cfont"><a class="cfont" href="#tag">[BURR, MEN, & COMPANY]</a></p>
                    The ship is in the harbor now</br>
                    See if you can spot him</br>
                    Just you wait</br>
                    Another immigrant</br>
                    Comin’ up from the bottom</br>
                    Just you wait</br>
                    His enemies destroyed his rep</br>
                    America forgot him</br>

我之前使用&lt;pre&gt;&lt;/pre&gt;,但注意到文本换行后出现水平滚动并且无法使其消失,因此我将其丢弃并选择使用&lt;br&gt;标签。

我遇到的问题是每一行都没有可用于添加&lt;br&gt; 标签的“共同点”。因此,我希望可以有一个正则表达式技巧来做到这一点,比如在每行之后检测一个空格?

不一定要一次性完成,我只是希望有一种更快的方法。

一个附带问题:有没有办法在这些纯文本的每一行添加idclass 而无需添加&lt;a&gt;&lt;p&gt; 标签?

提前非常感谢!

【问题讨论】:

  • 也许寻找 (.+)(?&lt;!&gt;)$ 并替换为 \1&lt;/br&gt;

标签: html regex notepad++


【解决方案1】:

使用

$(?<=.)(?<!>)

替换为&lt;br/&gt;

proof$(?&lt;=.)(?&lt;!&gt;) 将匹配任何在其前面有除换行符以外的字符且在后面没有 &gt; 字符的行尾位置。

【讨论】:

    猜你喜欢
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 2020-09-23
    • 2016-05-23
    相关资源
    最近更新 更多