英文:
RegEx - How to Add Anything After Selected Characters
问题
我正在尝试将 rel="nofollow noopener" target="_blank"
添加到HTML中的所有链接。
以下是示例HTML代码:
<li><a href="https://somewebsite.com/">Some website</a></li>
<li><a href="https://awesomewebsite.net/">Awesome Website</a></li>
<li><a href="https://coolwebsite.org/">Cool Website</a></li>
<p>Also <a href="https://badsite.com/">check this website</a></p>!
我对正则表达式一无所知,但在阅读了一些资源后,我已经编写了以下正则表达式:
href([^>]*)
这将选择所有链接,但我不确定如何在Notepad++中添加rel="nofollow noopener" target="_blank" 到我已经选择的部分
我正在尝试使用正则表达式将**rel="nofollow noopener" target="_blank"**添加到所有链接中。
英文:
I am trying to add rel="nofollow noopener" target="_blank"
to all the links in HTML.
Here's the example HTML code:
<li><a href="https://somewebsite.com/">Some website</a></li>
<li><a href="https://awesomewebsite.net/">Awesome Website</a></li>
<li><a href="https://coolwebsite.org/">Cool Website</a></li>
<p>Also <a href="https://badsite.com/">check this website</a></p>!
I know nothing about RegEx but after reading some resources I have written
href([^>]*)
Which selects all the links but I'm not sure how would I add rel="nofollow noopener" target="_blank" in Notepad++ after what I've selected
I am trying to add rel="nofollow noopener" target="_blank" to all the links with RegEx
答案1
得分: 0
让我们假设您打开了一个单个的HTML文件,您可以按照以下步骤进行。请小心使用这些选项,并在操作之前创建备份。
- <kbd>Ctrl</kbd>+<kbd>H</kbd>
- 查找内容:
(href([^>]*))
或缩写和更好的(href[^>]*)
- 替换为:
$1 target="_blank" rel="nofollow noopener"
- 搜索模式:正则表达式
- 单击<kbd>Replace All</kbd>(自担风险)
这将导致:
对于多个HTML文件,您可能需要尝试使用在文件中查找满足您的需求(<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>F</kbd>)。
英文:
Lets say you have a single HTML file open you'd go through following steps. Be careful with these options and create a backup beforehand.
- <kbd>Ctrl</kbd>+<kbd>H</kbd>
- Find what:
(href([^>]*))
or shortened and better(href[^>]*)
- Replace with:
$1 target="_blank" rel="nofollow noopener"
- Search mode: Regular expression
- Click on <kbd>Replace All</kbd> (at your own risk!)
This is resulting in:
For multiple HTML files, you may want to try Find in Files for your needs (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>F</kbd>).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论