2011-04-01 219 views
5

我想建立一個正則表達式來匹配任何git讀取和寫入URL結構(不只是GitHub),我想檢查是否得到了正確的正則表達式。這是我迄今爲止Git的URL結構

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

該正則表達式匹配所有下列URL

  • [email protected]:user/project.git
  • https://github.com/user/project.git
  • http://github.com/user/project.git
  • [email protected]: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

和其他類似非頂級域和單名域(HTTP://服務器/)。還有其他的網址結構,我應該明白嗎?還有一種更短的方式來編寫我現有的正則表達式嗎?

+0

AFAIK混帳可以處理_every_網址。 – KingCrunch 2011-04-01 20:25:44

+0

http://gitorious.org/ – 2011-04-01 20:25:54

+0

所以我應該真的只是驗證ssh或url? – 2011-04-01 20:29:31

回答