git存储库的正则表达式是什么?
示例链接:git@github.com:someone/someproject.git
所以它就像[user] @ [server]:[project] .git
服务器可以是url或ip项目可以包含除字母数字之外的其他一些字符,如' - '我不确定'/'的作用是什么
有什么建议?
Kel*_*aar 41
我正在使用以下正则表达式用于在线远程存储库:
((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)?
Jee*_*eet 10
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/
Run Code Online (Sandbox Code Playgroud)
对于我编写的需要解析这些表达式的应用程序(YonderGit),我提出了以下(Python)正则表达式:
(1) '(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)'
(2) 'file://(.*)'
(3) '(.+@)*([\w\d\.]+):(.*)'
Run Code Online (Sandbox Code Playgroud)
对于"在野外"遇到的大多数存储库URL,我怀疑(1)就足够了.