X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=extractor.go;h=19bc27472cea37b8466450dc342317bfa9e85650;hb=5083a5b6082be731123903af694a938d895a5a8f;hp=2a3b2cd5723d89593b5782e6782fa768b495c596;hpb=40e940f090b0036488c8254d062723b12a14efd7;p=path-extractor.git diff --git a/extractor.go b/extractor.go index 2a3b2cd..19bc274 100644 --- a/extractor.go +++ b/extractor.go @@ -1,6 +1,7 @@ package pathextractor import "regexp" +import "strings" import "fmt" type MatchOptions struct { @@ -8,7 +9,7 @@ type MatchOptions struct { } func pathExtractor(input string) [][][]byte { - surroundRegex := "[^][ \\t:'\"]*" + surroundRegex := "[^]()[ \\t:'\"]*" r := regexp.MustCompile("(" + surroundRegex + "[\\./]" + surroundRegex + ")") temp := [][][]byte{} temp = r.FindAllSubmatch([]byte(input), -1) @@ -38,6 +39,10 @@ func GetAllMatches(input string, options MatchOptions) []string { matches = pathExtractor(input) for _, match := range matches { s = string(match[1]) + if len(input) >= len(s+"(") && strings.Index(input, s+"(") != -1 { + continue + } + if isEmail(s) || isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || endsWithInvalidString(s) || containsInvalidString(s) || len(s) <= 2 { continue }