If you’re using Git for version control, you may want to know how to match Git repository URLs.
My problem was when I wanted to create a regex for this purpose. It took me hours before I found what I believe to be the best regex code for tasks like these. With this tutorial, hopefully, you’ll save yourself some time and make your job easier.
/((git|ssh|http(s)?)|([email protected][\w\.]+))(:(//)?)([\w\[email protected]\:/\-~]+)(\.git)(/)?/g
- [email protected]:microsoft/microsoft.git
- ssh://[email protected]/com:port/path/to/repo.git/
- [email protected]:~user/path/to/repo.git/