浏览代码

perf(validator): slightly optimize a regex

- There is no need to have groups as we're only using this regex for
  `MatchString`.
- Since the only place where this regex is used is already calling
  strings.ToLower, there is no need to check for `A-Z`.
jvoisin 1 年之前
父节点
当前提交
0086e0b356
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      internal/validator/validator.go

+ 1 - 1
internal/validator/validator.go

@@ -10,7 +10,7 @@ import (
 	"strings"
 	"strings"
 )
 )
 
 
-var domainRegex = regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$`)
+var domainRegex = regexp.MustCompile(`^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$`)
 
 
 // ValidateRange makes sure the offset/limit values are valid.
 // ValidateRange makes sure the offset/limit values are valid.
 func ValidateRange(offset, limit int) error {
 func ValidateRange(offset, limit int) error {