From 09acd79fe8b6be49c62cd4bdef52b3903cdd4980 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sat, 15 Jan 2022 19:57:38 +0100 Subject: [PATCH] remove regex lookaround --- envconf.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/envconf.go b/envconf.go index da14de4..780c499 100644 --- a/envconf.go +++ b/envconf.go @@ -259,7 +259,7 @@ func (c *Config) Status() (ok bool) { } func cleanKey(key string) string { - expr := regexp.MustCompile("(?:^_+)|(?:_+(?=_))|(?:_$)") + expr := regexp.MustCompile("__+") fn := func(r rune) rune { if (r >= '0' && r <= '9') || (r >= 'A' && r <= 'Z') || r == '_' { return r @@ -267,8 +267,8 @@ func cleanKey(key string) string { return -1 } - key = strings.Map(fn, strings.ToUpper(key)) - return expr.ReplaceAllString(key, "") + key = strings.Trim(strings.Map(fn, strings.ToUpper(key)), "_") + return expr.ReplaceAllString(key, "_") } func keySplit(key string) (left string, right string, ok bool) {