From cd09b2fd8f543fd6941a6be0ba2b543cc8d05fad Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 10 Jun 2025 17:33:00 +0200 Subject: [PATCH] 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`. --- internal/validator/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/validator/validator.go b/internal/validator/validator.go index 9b3cfd90..044123e1 100644 --- a/internal/validator/validator.go +++ b/internal/validator/validator.go @@ -10,7 +10,7 @@ import ( "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. func ValidateRange(offset, limit int) error {