fix domain re

This commit is contained in:
zu1k 2021-03-26 16:28:41 +08:00
parent 8319d3591d
commit 710597802b
2 changed files with 25 additions and 4 deletions

View File

@ -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() {

23
internal/app/re_test.go Normal file
View File

@ -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))
}
}