What will be proper regular expression for git repositories?
example link: git@github.com:someone/someproject.git
so it will be like [user]@[server]:[project].git
server can be url or ip Project can contain some other characters than alphanumeric like '-' I'm not sure what is the role of '/'
any suggestions?
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/
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\.]+):(.*)'
For most repository URL's encountered "in the wild", I suspect (1) suffices.
This does not work with a url like git@abc.def.xyz:group/project.git