Regex To Match Git Repositories

Category: URI

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

Matches:

Non-matches:

See Also:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.
Category: URI