温馨提示:本文翻译自stackoverflow.com,查看原文请点击:regex - Regular expression for git repository
git regex

regex - git存储库的正则表达式

发布于 2020-03-27 16:04:51

git存储库的正确正则表达式是什么?

示例链接:git@github.com:someone / someproject.git

这样就好像[user] @ [server]:[project] .git

服务器可以是url或ip项目可以包含字母数字以外的其他字符,例如“-”,我不确定“ /”的作用是什么

有什么建议么?

查看更多

查看更多

提问者
dfens
被浏览
190
Jeet 2010-03-25 19:24

Git接受大量的存储库URL表达式:

* 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)正则表达式:

    (1) '(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)'
    (2) 'file://(.*)'       
    (3) '(.+@)*([\w\d\.]+):(.*)'

对于大多数“在野外”遇到的URL,我怀疑(1)就足够了。