git存储库的正则表达式

dfe*_*ens 16 regex

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

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

所以它就像[user] @ [server]:[project] .git

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

有什么建议?

Kel*_*aar 41

我正在使用以下正则表达式用于在线远程存储库:

((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)?

在Debuggex上查看

正则表达式可视化

  • 我来到这里寻找正则表达式声明,所以我没有花时间在它上面,我发现了有史以来最好的正则表达式调试器.谢谢. (9认同)
  • 我同意 Debuggex 的观点。不幸的是,上面表达式中的组 4 不处理“git”以外的用户。 (2认同)

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)就足够了.

  • 这不适用于像git@abc.def.xyz这样的网址:group/project.git (2认同)