如何在 Notepad++ 中使用正则表达式在现有文本的每一行中添加文本?
How to add a text in every line with an existing texts using regex in Notepad++?
是否可以在 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>
我之前用的是<pre></pre>
,但是发现文字换行后出现了水平滚动条,无法让它消失,所以我放弃了,会选择使用<br>
标签。
我遇到的问题是我可以用来添加 <br>
标签的每一行都没有“共同点”。因此,我希望可以有一个正则表达式技巧来做到这一点,比如在每行之后检测一个空的 space?
不必一次完成,我只是希望有更快的方法。
附带问题:有没有办法在不添加 <a>
或 <p>
标签的情况下向这些纯文本的每一行添加 id
或 class
?
非常感谢!
使用
$(?<=.)(?<!>)
替换为<br/>
。
参见proof。 $(?<=.)(?<!>)
将匹配前面有除换行符以外的字符且后面没有 >
个字符的任何行尾位置。
是否可以在 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>
我之前用的是<pre></pre>
,但是发现文字换行后出现了水平滚动条,无法让它消失,所以我放弃了,会选择使用<br>
标签。
我遇到的问题是我可以用来添加 <br>
标签的每一行都没有“共同点”。因此,我希望可以有一个正则表达式技巧来做到这一点,比如在每行之后检测一个空的 space?
不必一次完成,我只是希望有更快的方法。
附带问题:有没有办法在不添加 <a>
或 <p>
标签的情况下向这些纯文本的每一行添加 id
或 class
?
非常感谢!
使用
$(?<=.)(?<!>)
替换为<br/>
。
参见proof。 $(?<=.)(?<!>)
将匹配前面有除换行符以外的字符且后面没有 >
个字符的任何行尾位置。