Browse Source

正则中文支持

zhangjinkun 6 years ago
parent
commit
26c5eabed2
3 changed files with 19 additions and 0 deletions
  1. 6 0
      src/jy/admin/rulecheck.go
  2. 12 0
      src/jy/extract/extractInit.go
  3. 1 0
      src/main_test.go

+ 6 - 0
src/jy/admin/rulecheck.go

@@ -199,6 +199,8 @@ func checkPreReg(content, ruleText string) string {
 		var pattern string
 		if strings.Contains(tmp[0], "\\u") {
 			pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+		} else {
+			pattern = tmp[0]
 		}
 		if len(tmp) == 2 {
 			reg := regexp.MustCompile(pattern)
@@ -221,6 +223,8 @@ func checkBackReg(content, ruleText string) string {
 		var pattern string
 		if strings.Contains(tmp[0], "\\u") {
 			pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+		} else {
+			pattern = tmp[0]
 		}
 		if len(tmp) == 2 {
 			reg := regexp.MustCompile(pattern)
@@ -255,6 +259,8 @@ func checkCoreReg(field, content, ruleText string) map[string]string {
 			var pattern string
 			if strings.Contains(tmp[0], "\\u") {
 				pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+			} else {
+				pattern = tmp[0]
 			}
 			reg := regexp.MustCompile(pattern)
 			apos := reg.FindAllStringSubmatchIndex(content, -1)

+ 12 - 0
src/jy/extract/extractInit.go

@@ -205,6 +205,8 @@ func (e *ExtractTask) InitRulePres() {
 				var pattern string
 				if strings.Contains(tmp[0], "\\u") {
 					pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+				} else {
+					pattern = tmp[0]
 				}
 				if len(tmp) == 2 {
 					rinfo.RegPreBac = &ExtReg{Reg: regexp.MustCompile(pattern), Replace: tmp[1]}
@@ -240,6 +242,8 @@ func (e *ExtractTask) InitRuleBacks() {
 				var pattern string
 				if strings.Contains(tmp[0], "\\u") {
 					pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+				} else {
+					pattern = tmp[0]
 				}
 				if len(tmp) == 2 {
 					rinfo.RegPreBac = &ExtReg{Reg: regexp.MustCompile(pattern), Replace: tmp[1]}
@@ -294,6 +298,8 @@ func (e *ExtractTask) InitRuleCore() {
 						var pattern string
 						if strings.Contains(tmp[0], "\\u") {
 							pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+						} else {
+							pattern = tmp[0]
 						}
 						if len(tmp) == 2 {
 							rinfo.RegPreBac = &ExtReg{Reg: regexp.MustCompile(pattern), Replace: tmp[1]}
@@ -328,6 +334,8 @@ func (e *ExtractTask) InitRuleCore() {
 						var pattern string
 						if strings.Contains(tmp[0], "\\u") {
 							pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+						} else {
+							pattern = tmp[0]
 						}
 						if len(tmp) == 2 {
 							rinfo.RegPreBac = &ExtReg{Reg: regexp.MustCompile(pattern), Replace: tmp[1]}
@@ -367,6 +375,8 @@ func (e *ExtractTask) InitRuleCore() {
 						var pattern string
 						if strings.Contains(tmp[0], "\\u") {
 							pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+						} else {
+							pattern = tmp[0]
 						}
 						if len(tmp) == 2 {
 							epos := strings.Split(tmp[1], ",")
@@ -436,6 +446,8 @@ func (e *ExtractTask) InitPkgCore() {
 						var pattern string
 						if strings.Contains(tmp[0], "\\u") {
 							pattern, _ = strconv.Unquote(`"` + tmp[0] + `"`)
+						} else {
+							pattern = tmp[0]
 						}
 						if len(tmp) == 2 {
 							rinfo.RegPreBac = &ExtReg{Reg: regexp.MustCompile(pattern), Replace: tmp[1]}

+ 1 - 0
src/main_test.go

@@ -8,6 +8,7 @@ import (
 	. "jy/mongodbutil"
 	"log"
 	"regexp"
+	"strconv"
 	"testing"
 	"time"
 )