gpt4 book ai didi

regex - 使用正则表达式从AWS S3 URL中提取存储桶名称

转载 作者:行者123 更新时间:2023-12-03 10:08:38 24 4
gpt4 key购买 nike

我想从AWS s3 URL中提取存储桶名称。
URL可以采用多种格式。以下是受支持的s3 URL的正则表达式列表:

[a-z0-9.-]+\.s3\.amazonaws\.com
[a-z0-9.-]+\.s3-[a-z0-9-]+\.amazonaws\.com
[a-z0-9.-]+\.s3\.[a-z0-9-]+\.amazonaws\.com
[a-z0-9.-]+\.s3-website[.-](eu|ap|us|ca|sa|cn)
例子:
bucket-name.s3.us-west-2.amazonaws.com
bucket.name.s3.us-west-2.amazonaws.com
bucket-name.s3-us-west-2.amazonaws.com
bucket.name.s3-us-west-2.amazonaws.com
bucket-name.s3.amazonaws.com
bucket.name.s3.amazonaws.com
我想要一个可以从 bucket-name中的这些URL中提取 GoLang的正则表达式。

最佳答案

这将工作:

^(.+)(?:\.s3[-.].*)$
已翻译:

From the beginning of the string find everything leading up to .s3. or .s3- and capture it into group #1.


您的存储桶名称将在 $1中。
请参阅下面的regex101链接,并使用代码生成器查看Golang示例。
https://regex101.com/r/LRvA5F/1

关于regex - 使用正则表达式从AWS S3 URL中提取存储桶名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64557427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com