diff --git a/internal/app/cdn.go b/internal/app/cdn.go index 066d420..c9748e4 100644 --- a/internal/app/cdn.go +++ b/internal/app/cdn.go @@ -7,10 +7,8 @@ import ( "regexp" "strings" - "github.com/zu1k/nali/internal/tools" - "github.com/zu1k/nali/constant" - + "github.com/zu1k/nali/internal/tools" "github.com/zu1k/nali/pkg/cdn" ) @@ -20,7 +18,7 @@ var ( ) func init() { - domainRe = regexp.MustCompile(`[0-9A-Za-z]{2,}\.[0-9A-Za-z]{2,3}\.[0-9A-Za-z]{2,3}|[0-9A-Za-z]{2,}\.[0-9A-Za-z]{2,3}`) + domainRe = regexp.MustCompile(`[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+`) } func InitCDNDB() { diff --git a/internal/app/re_test.go b/internal/app/re_test.go new file mode 100644 index 0000000..9cb7e36 --- /dev/null +++ b/internal/app/re_test.go @@ -0,0 +1,23 @@ +package app + +import ( + "fmt" + "testing" +) + +var domainList = []string{ + "a.a.qiniudns.com", + "a.com.qiniudns.com", + "a.com.cn.qiniudns.com", + "看这里:a.com.cn.qiniudns.com行不行", +} + +func TestDomainRe(t *testing.T) { + for _, domain := range domainList { + if !domainRe.MatchString(domain) { + t.Error(domain) + t.Fail() + } + fmt.Println(domainRe.FindAllString(domain, -1)) + } +}