gpt4 book ai didi

正则表达式解析docker标签?

转载 作者:行者123 更新时间:2023-12-04 23:16:41 25 4
gpt4 key购买 nike

'registry/rabbit',
'registry/rabbit:3',
'rabbit',
'rabbit:3'

试图想出一个匹配 rabbit 的正则表达式在上述四种情况下。看起来很容易,但我的正则表达式让我失望。

最佳答案

格式有点不明确,但这似乎有效:

^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?/)?((?![._-])(?:[a-z0-9._-]*)(?<![._-])(?:/(?![._-])[a-z0-9._-]*(?<![._-]))*)(?::(?![.-])[a-zA-Z0-9_.-]{1,128})?$
来自 docs :

An image name is made up of slash-separated name components, optionally prefixed by a registry hostname. The hostname must comply with standard DNS rules, but may not contain underscores. If a hostname is present, it may optionally be followed by a port number in the format :8080. If not present, the command uses Docker’s public registry located at registry-1.docker.io by default. Name components may contain lowercase characters, digits and separators. A separator is defined as a period, one or two underscores, or one or more dashes. A name component may not start or end with a separator.

A tag name may contain lowercase and uppercase characters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.


测试是 here .

关于正则表达式解析docker标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39671641/

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