]> Sergey Matveev's repositories - path-extractor.git/blob - extractor.go
d42bf0e0032767a5203c4f5ae72383dd0385436f
[path-extractor.git] / extractor.go
1 package pathextractor
2
3 import "regexp"
4
5 func pathExtractor(input string) [][][]byte {
6         surroundRegex := "[^][ \\t:'\"]"
7         r := regexp.MustCompile("(" + surroundRegex + "*[\\./]" + surroundRegex + "*)")
8         temp := [][][]byte{}
9         temp = r.FindAllSubmatch([]byte(input), -1)
10         return temp
11 }
12
13 func GetAllMatches(input string) []string {
14         matches := [][][]byte{}
15         result := []string{}
16         s := string("")
17         matches = pathExtractor(input)
18         for _, match := range matches {
19                 s = string(match[1])
20                 if isEmail(s) || isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || endsWithInvalidString(s) || containsInvalidString(s) || len(s) <= 2 {
21                         continue
22                 }
23                 if isGitPath(s) {
24                         s = replaceGitPath(s)
25                 }
26                 result = append(result, s)
27         }
28         return result
29 }