From 22bf132efb1cddb972c044b262e749cccf4f8dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 29 Mar 2023 20:06:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIP=E5=BA=93=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/iplibrary/template.go | 2 +- pkg/iplibrary/template_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/iplibrary/template.go b/pkg/iplibrary/template.go index 76b3eec..e6ab7d5 100644 --- a/pkg/iplibrary/template.go +++ b/pkg/iplibrary/template.go @@ -38,7 +38,7 @@ func (this *Template) init() error { return keyword }) - reg, err := regexp.Compile(template) + reg, err := regexp.Compile("^(?U)" + template) if err != nil { return err } diff --git a/pkg/iplibrary/template_test.go b/pkg/iplibrary/template_test.go index 61212c1..b4762a4 100644 --- a/pkg/iplibrary/template_test.go +++ b/pkg/iplibrary/template_test.go @@ -23,3 +23,16 @@ func TestNewTemplate(t *testing.T) { t.Log(s, "=>\n", values) } } + +func TestNewTemplate2(t *testing.T) { + template, err := iplibrary.NewTemplate("${any},${any},${ipFrom},${ipTo},${country},${province},${city},${town},${provider},${any},${any}") + if err != nil { + t.Fatal(err) + } + for _, s := range []string{ + "22723584,22723839,1.90.188.0,1.90.188.255,中国,北京,北京,房山,歌华有线,102400,010,城域网", + } { + values, _ := template.Extract(s, []string{}) + t.Log(s, "=>\n", values) + } +}