通过正则表达式从记事本+++中的相同类型的URL中提取所需的部分

Extract the required part from same type of URLs in notepad+++ by regex

我有一个来自同一网站的 URL 列表。如何在 Notepad++ 中使用正则表达式提取其中的特定部分?

以下是部分网址:

https://www.example.in/example/MT60B2G8HB-48BA-TR?qs=iLbezkQI%252BsgqYFd1yfooJw%3D%3D
https://www.example.in/example/AT25L128A-MHE-T?qs=IS%252B4QmGtzzoXQyQfwYv36A%3D%3D

所有类似类型的 URL 的输出应该是 MT60B2G8HB-48BA-TRAT25L128A-MHE-T

如果所有 URL 都具有相同的 url,直到最后一部分的路径并且始终具有 GET-parameters(使用 ?),那么您可以使用:

"(?<=https://www.example.in/example/)[^?]+"
# match any string that has https://www.example.in/example/ before it until the first ?

如果url是否有GET-params可选:

"(?<=https://www.example.in/example/)[^?\s]+"
# match any string that has https://www.example.in/example/ before it until the first ? or whitespace/linebreak

以下将允许您搜索 模式(当然是在正则表达式模式下):

(?<=https://www.example.in/example/).*(?=\?)

(?<=...) 称为正后视,必须是位于您要查找的内容之前的固定模式

(?=...) 称为正向前瞻,必须是位于您要查找的内容之后的固定模式(此处第一个 '?' 用 '\' 转义)

如果你想替换模式,那么你可以简化为这个。

查找内容:https://www.example.in/example/(.*)\?.*
替换为:

一如既往的简短选择

查找:^.*/(.*?)\?.*

替换为: