的 URL 部分-6ren"> 的 URL 部分-我想修改 .html 和 .txt 文件中包含的许多链接。我主要使用 Kate 作为我的文本编辑器,因此我用 kate 标签问了这个问题。以下是链接示例: sK1 -6ren">
gpt4 book ai didi

html - kate - 正则表达式 - 查找并替换从 href 到 "> 的 URL 部分

转载 作者:行者123 更新时间:2023-11-27 22:57:00 24 4
gpt4 key购买 nike

我想修改 .html 和 .txt 文件中包含的许多链接。我主要使用 Kate 作为我的文本编辑器,因此我用 kate 标签问了这个问题。以下是链接示例:

<li>
<a href="http://sk1project.org/">
sK1
</a> is an open source vector graphics editor similar to CorelDRAW, Adobe Illustrator, or Freehand. First of all sK1 is oriented for PostScript processing. UniConvertor is a universal vector graphics translator. It uses sK1 engine to convert
one format to another. Development of the import/export modules for this program goes through different stages, quality and feature coverage are different among formats.
</li>


<li>
<a href="http://tango.freedesktop.org/Tango_Desktop_Project">
The Tango Desktop Project
</a> exists to help create a consistent graphical user interface experience for free and Open Source software. While the look and feel of an application is determined by many individual components, some organization is necessary in order to
unify the appearance and structure of individual icon sets used within those components. The Tango Desktop Project defines an icon style guideline to which artists and designers can adhere. A sample implementation of the style is available as an icon
theme based upon a standardized icon naming specification. In addition, the project provides transitional utilities to assist in creating icon themes for existing desktop environments, such as GNOME and KDE.
</li>

我发现 Regular expression to extract URL from an HTML link | python - 从 HTML 链接中提取 URL 的正则表达式 - 堆栈溢出所以我知道如何使用 href=[\'"]?([^\'">]+"> 从 href 捕获文本到 "> ),但我不知道如何在 > 之前将文本从 href 保留为 "并添加以下文本:' rel="nofollow noopener noreferrer">'。

我知道最终结果应该如下所示:

<li>
<a href="http://sk1project.org/" rel="nofollow noopener noreferrer">
sK1
</a> is an open source vector graphics editor similar to CorelDRAW, Adobe Illustrator, or Freehand. First of all sK1 is oriented for PostScript processing. UniConvertor is a universal vector graphics translator. It uses sK1 engine to convert
one format to another. Development of the import/export modules for this program goes through different stages, quality and feature coverage are different among formats.
</li>


<li>
<a href="http://tango.freedesktop.org/Tango_Desktop_Project" rel="nofollow noopener noreferrer">
The Tango Desktop Project
</a> exists to help create a consistent graphical user interface experience for free and Open Source software. While the look and feel of an application is determined by many individual components, some organization is necessary in order to
unify the appearance and structure of individual icon sets used within those components. The Tango Desktop Project defines an icon style guideline to which artists and designers can adhere. A sample implementation of the style is available as an icon
theme based upon a standardized icon naming specification. In addition, the project provides transitional utilities to assist in creating icon themes for existing desktop environments, such as GNOME and KDE
</li>

如何在 Kate 中使用正则表达式完成此操作?

谢谢。

最佳答案

不推荐使用正则表达式解析 html,但因为您使用的是 Kate编辑器,您可以捕获 <ahref 标记使用此正则表达式的属性,

(<a\s+.*?href=(['"]?)\S*\2)

并用这个替换它,

\1 rel="nofollow noopener noreferrer"

我从未使用过 Kate 编辑器,所以不确定是否 \1将工作或$1

让我知道这是否有效。

Demo

关于html - kate - 正则表达式 - 查找并替换从 href 到 "> 的 URL 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55186546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com