【问题标题】:how to trim a list of urls to first folder如何将网址列表修剪到第一个文件夹
【发布时间】:2021-03-18 18:30:49
【问题描述】:

我想修剪第一个文件夹的 url 列表

for example:
url.com/folder1/xxx/index.html
url.com/folder2/
url.com/folder3/xxx/yyyy/index.html
url.com/folder4/zzz/aaa/bbb/index.html

Output should look like this:
url.com/folder1/
url.com/folder2/
url.com/folder3/
url.com/folder4/

任何帮助将不胜感激。 谢谢!

【问题讨论】:

  • 到目前为止你尝试过什么?您没有提供有关 如何 应该完成的任何详细信息,输出应该去哪里等。您的问题被标记为 [regex[ 和 [notepad++],但除此之外,我们没有您的问题的上下文。
  • 我尝试在 scrapebox 中执行此操作,但它只修剪到最后一个文件夹而不是第一个。我没有使用 notepad++ 或正则表达式的经验,在谷歌上搜索没有运气。
  • 这能回答你的问题吗? Reference - What does this regex mean?

标签: regex string url url-rewriting notepad++


【解决方案1】:

查找内容:

^([^/]*/[^/]*/).*

如有必要,请转义正斜杠。

^([^\/]*\/[^\/]*\/).*

替换为:

\1

DEMO

【讨论】:

  • 在替换字符串的开头添加hhtp://。见regex101.com/r/aS7zX3/3
  • 对不起,我是新来的……我刚注册的时候太光秃了:)……我想说的是,如果原始网址中有 http:// .. .so (url.com/folder1/zzz/index.html) -> (url.com/folder1)。我无法在原始帖子中添加 http://,因为我是新用户,我不能发布超过 1 或 2 个网址。
【解决方案2】:

查找: ^.*?\/.*?\/\K.*$

试试这个。替换为 empty string。查看演示。

https://regex101.com/r/mS3tQ7/14

\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 2020-12-16
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多