簡體   English   中英

kate - 正則表達式 - 查找並替換從 href 到 "> 的 URL 部分

[英]kate - regex - find and replace portion of URL from href to ">

我想修改 .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>

我發現正則表達式可以從 HTML 鏈接中提取 URL | 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編輯器,因此您可以使用此正則表達式捕獲帶有href屬性的<a標簽,

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

並用這個替換它,

\1 rel="nofollow noopener noreferrer"

我從未使用過 Kate 編輯器,所以不確定\\1是否有效或$1

讓我知道這個是否奏效。

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM