// clear package main import ( "regexp" "strings" ) var at = rune('&') var ed = rune(';') var lableMap = map[string]rune{ "&": rune('&'), " ": rune(' '), ">": rune('>'), "<": rune('<'), } func CleanString(input string) string { reg := regexp.MustCompile("[^a-zA-Z0-9\u4e00-\u9fa5]+") cleaned := reg.ReplaceAllString(input, "") return cleaned } // 清洗正文 func CleanDetailText(detail string) string { detail = regexp.MustCompile(``).ReplaceAllString(detail, "") detail = regexp.MustCompile(``).ReplaceAllString(detail, "") detail = CutLableStr(detail) return detail } //处理转义标签 func CutLableStr(con string) string { for i := 0; i < 3; i++ { runes := []rune{} pools := []rune{} bpool := false strings.IndexFunc(con, func(s rune) bool { if !bpool && s == at { bpool = true pools = []rune{} } if bpool { pools = append(pools, s) if s == ed { //结束 lb := lableMap[string(pools)] if lb != 0 { runes = append(runes, lb) } else { runes = append(runes, pools...) } bpool = false } else if len(pools) > 6 { bpool = false runes = append(runes, pools...) } } else { runes = append(runes, s) } return false }) str1 := string(runes) if i > 0 && con == str1 { break } con = str1 } return con }