我想修改.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=[\'"]?([^\'" >]+">)从ref到“>捕获文本,但我不知道如何保持ref到”的文本在>之前,并添加以下文本:“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>

凯特身上的regex怎么办?
谢谢您。

最佳答案

不建议使用regex解析html,但由于您使用的是Kate编辑器,因此可以使用此regex捕获带有<a属性的href标记,

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

换成这个,
\1 rel="nofollow noopener noreferrer"

我从来没有用过Kate编辑器,所以不确定\1是否可以工作或$1
让我知道这是否有效。
Demo

08-05 18:08