开发者

Git URL Structure

I am trying to build a regular expression to match any git read+write URL structure (not just GitHub) and I wanted to check to see if I got the regex right. This is what I have so far

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

That regex 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 like non-top-level domains and single name domains (http://server/). Are there other url structures that I should be concious of? Also is there a shorter way of writing the existing regex that I have?


If you are using rails / ruby to write your program, check this out. You might be able to get some ideas from here:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜