git存储库的正则表达式 [英] Regular expression for git repository
问题描述
git存储库的正确正则表达式是什么?
What will be proper regular expression for git repositories?
示例链接: git@github.com:someone/someproject.git
example link: git@github.com:someone/someproject.git
所以会像 [用户] @ [服务器]:[项目] .git
so it will be like [user]@[server]:[project].git
服务器可以是url或ip 项目中可以包含字母数字以外的其他字符,例如-" 我不确定'/'的作用是什么
server can be url or ip Project can contain some other characters than alphanumeric like '-' I'm not sure what is the role of '/'
有什么建议吗?
推荐答案
Git接受大量的存储库URL表达式:
Git accepts a large range of repository URL expressions:
* ssh://user@host.xz:port/path/to/repo.git/
* ssh://user@host.xz/path/to/repo.git/
* ssh://host.xz:port/path/to/repo.git/
* ssh://host.xz/path/to/repo.git/
* ssh://user@host.xz/path/to/repo.git/
* ssh://host.xz/path/to/repo.git/
* ssh://user@host.xz/~user/path/to/repo.git/
* ssh://host.xz/~user/path/to/repo.git/
* ssh://user@host.xz/~/path/to/repo.git
* ssh://host.xz/~/path/to/repo.git
* user@host.xz:/path/to/repo.git/
* host.xz:/path/to/repo.git/
* user@host.xz:~user/path/to/repo.git/
* host.xz:~user/path/to/repo.git/
* user@host.xz:path/to/repo.git
* host.xz:path/to/repo.git
* rsync://host.xz/path/to/repo.git/
* git://host.xz/path/to/repo.git/
* git://host.xz/~user/path/to/repo.git/
* http://host.xz/path/to/repo.git/
* https://host.xz/path/to/repo.git/
* /path/to/repo.git/
* path/to/repo.git/
* ~/path/to/repo.git
* file:///path/to/repo.git/
* file://~/path/to/repo.git/
对于我编写的需要解析这些表达式的应用程序( YonderGit ),我想到了以下内容(Python)正则表达式:
For an application that I wrote that requires parsing of these expressions (YonderGit), I came up with the following (Python) regular expressions:
(1) '(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)'
(2) 'file://(.*)'
(3) '(.+@)*([\w\d\.]+):(.*)'
对于大多数在野外"遇到的存储库URL,我怀疑(1)就足够了.
For most repository URL's encountered "in the wild", I suspect (1) suffices.
这篇关于git存储库的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!