package clean import ( "regexp" "strings" "unicode" "unicode/utf8" ) // 限制 var codeUnConReg *regexp.Regexp = regexp.MustCompile("(null|勘察|包件|测试|设计|设备|项目|标段|工程|监理|范围|分包|月|日|天)") var codeUnLenReg *regexp.Regexp = regexp.MustCompile("([\u4e00-\u9fa5]{7,})") // 符合 var codeMeetReg1 *regexp.Regexp = regexp.MustCompile("(第[0-9]+号)") // 清洗项目编号 func CleanPcode(pcode string, fns []string) string { if utf8.RuneCountInString(pcode) < 5 { return "" } pcode = fieldReg1.ReplaceAllString(pcode, "") pcode = pcodeReg1.ReplaceAllString(pcode, "") pcode = pcodeReg2.ReplaceAllString(pcode, "") //符合条件 if codeMeetReg1.MatchString(pcode) { return pcode } //舍弃条件 if codeUnConReg.MatchString(pcode) || codeUnLenReg.MatchString(pcode) || !isAlphanumeric(pcode) || isRegTimeDateCode(pcode) { return "" } //校验与附件名字否是一致-舍弃 for _, v := range fns { if utf8.RuneCountInString(v) >= utf8.RuneCountInString(pcode) { if strings.Contains(v, pcode) { return "" } } } return pcode } // 清洗其他编号 func CleanOtherCode(ocode string) string { if utf8.RuneCountInString(ocode) < 5 { return "" } ocode = fieldReg1.ReplaceAllString(ocode, "") ocode = pcodeReg1.ReplaceAllString(ocode, "") ocode = pcodeReg2.ReplaceAllString(ocode, "") //符合条件 if codeMeetReg1.MatchString(ocode) { return ocode } //舍弃条件 if codeUnConReg.MatchString(ocode) || codeUnLenReg.MatchString(ocode) || !isAlphanumeric(ocode) || isRegTimeDateCode(ocode) { return "" } return ocode } // 是否含字母数字 func isAlphanumeric(str string) bool { var count int for _, v := range str { if unicode.IsNumber(v) || unicode.IsLetter(v) { count++ break } } return count > 0 } // 连续数字 func isRegTimeDateCode(str string) bool { reg := `\d{8}` regx, _ := regexp.Compile(reg) if regx.FindString(str) != "" { return false } if utf8.RuneCountInString(str) == 8 { return true } return false }