File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ const (
2929 ISBN10Pattern = `(?:[\d]-?){9}[\dxX]`
3030 MACAddressPattern = `(([a-fA-F0-9]{2}[:-]){5}([a-fA-F0-9]{2}))`
3131 IBANPattern = `[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z\d]?){0,16}`
32+ GitRepoPattern = `((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:/\-~]+)(\.git)(\/)?`
3233)
3334
3435var (
5859 MCCreditCardRegex = regexp .MustCompile (MCCreditCardPattern )
5960 MACAddressRegex = regexp .MustCompile (MACAddressPattern )
6061 IBANRegex = regexp .MustCompile (IBANPattern )
62+ GitRepoRegex = regexp .MustCompile (GitRepoPattern )
6163)
6264
6365func match (text string , regex * regexp.Regexp ) []string {
@@ -168,3 +170,7 @@ func MACAddresses(text string) []string {
168170func IBANs (text string ) []string {
169171 return match (text , IBANRegex )
170172}
173+
174+ func GitRepos (text string ) []string {
175+ return match (text , GitRepoRegex )
176+ }
Original file line number Diff line number Diff line change @@ -635,3 +635,28 @@ func TestCommonRegex_IBANs(t *testing.T) {
635635 assert .NotEqual ([]string {test }, parsed , "they should not be matched" )
636636 }
637637}
638+
639+ func TestCommonRegex_GitRepos (t * testing.T ) {
640+ t .Parallel ()
641+ assert := assert .New (t )
642+
643+ tests := []string {
644+ "https://github.com/mingrammer/commonregex.git" ,
645+ "git@github.com:mingrammer/commonregex.git" ,
646+ }
647+
648+ failingTests := []string {
649+ "https://github.com/mingrammer/commonregex" ,
650+ "test@github.com:mingrammer/commonregex.git" ,
651+ }
652+
653+ for _ , test := range tests {
654+ parsed := GitRepos (test )
655+ assert .Equal ([]string {test }, parsed , "they should be matched" )
656+ }
657+
658+ for _ , test := range failingTests {
659+ parsed := GitRepos (test )
660+ assert .NotEqual ([]string {test }, parsed , "they should not be matched" )
661+ }
662+ }
You can’t perform that action at this time.
0 commit comments