简体   繁体   English

Notepad ++中的RegEx删除或替换文本范围

[英]RegEx in Notepad++ To Remove or Replace Range of Text

I just go through the RegEx answers to the questions by other mates but couldn't find any solution for the problem in my case. 我只是通过RegEx回答了其他配偶的问题,但在我的情况下找不到任何解决方案。 I also read the Regular Expressions references given by some of the helpers here but I was not able to understand properly. 我还阅读了一些帮助者在此处提供的正则表达式参考,但我无法正确理解。

I am editing my sitemaps of websites. 我正在编辑网站的站点地图。 In the sitemap, I have some links in the form: 在站点地图中,我具有以下形式的链接:

http://foo.com/download/something-after-download-different-for-each-link-12-23-2014.html?id=my5sIUosfiQ&itag=18

And I want to change all those links to simply: 我想将所有这些链接更改为:

http://foo.com/download/?id=my5sIUosfiQ&itag=18

Here, ?id= and itag= values are different for each link. 在此,每个链接的?id=itag=值都不同。 So, these should not get changed for each link which are already mentioned. 因此,对于已经提到的每个链接,这些都不应更改。

Plus, the part something-after-download-different-for-each-link-12-23-2014.html is also different for each link as every file is different to download. 另外, something-after-download-different-for-each-link-12-23-2014.html部分something-after-download-different-for-each-link-12-23-2014.html )部分也有所不同,因为每个文件的下载方式都不相同。 So, I want to basically remove the this part from each link. 因此,我想从每个链接中基本上删除此部分。 How can I do this? 我怎样才能做到这一点?

Some things that might work - 一些可能有效的方法-
( Note that the odds of finding an errant /download/ not followed 请注意,不遵循错误查找/download/的可能性
by non-whitespace nor question mark, then a question mark, 通过非空格或问号,然后是问号,
make this virtually impossible to match anything other than the url's ) 使其几乎无法与url以外的其他任何内容匹配

If np++ uses the \\K construct you could use this 如果np ++使用\\K构造,则可以使用
Find: /download/\\K[^\\s?]+(?=\\?) 查找: /download/\\K[^\\s?]+(?=\\?)
Replace: nothing 更换:无

If it doesn't, you could use this 如果没有,您可以使用它
Find: (?<=/download/)[^\\s?]+(?=\\?) 查找: (?<=/download/)[^\\s?]+(?=\\?)
Replace: nothing 更换:无

or, even better 甚至更好
Find: (/download/)[^\\s?]+(?=\\?) 查找: (/download/)[^\\s?]+(?=\\?)
Replace: $1 更换: $1

You should find 你应该找到

http://foo\.com/download/[^?]*\?id=(.*)

and replace it with 并替换为

http://foo\.com/download/\?$1

This grabs everything between ...download/ and ?id=... and removes it. 这将抓取...download/?id=...之间的所有内容并将其删除。

Enable regex and use this search & replace: 启用正则表达式并使用此搜索并替换:

Find: 找:

(http://foo.com/download/)(.*)(\?id=my5sIUosfiQ&amp;itag=18)

Replace with: 用。。。来代替:

\1\3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM