Git URL Structure

I am trying to create a regular expression to match any git read + write URL structure (not just GitHub), and I wanted to check if I got the correct expression correctly. This is what I still have

([A-Za-z0-9]+@|http(|s)\:\/\/)([A-Za-z0-9.]+)(:|/)([A-Za-z0-9\/]+)(\.git)?

This regular expression matches all of the following URLs

  • git@github.com:user/project.git
  • https://github.com/user/project.git
  • http://github.com/user/project.git
  • git@192.168.101.127:user/project.git
  • https://192.168.101.127/user/project.git
  • http://192.168.101.127/user/project.git
  • http://192.168.101.127/user/project

And others, such as top-level domains and domains with the same name (http: // server /). Are there other url structures I should keep in mind? Also, is there a shorter way of writing an existing regular expression that I have?

+5
source share
1 answer

If you use rails / rubies to write your program, check this out. You could get some ideas from here:

http://www.simonecarletti.com/blog/2009/04/validating-the-format-of-an-url-with-rails/

0

All Articles