Closed hapiman closed 6 years ago
func SplitByPunctuation(s string) ([]string, []string) { regPunctuation, _ := regexp.Compile(`[,,。.??!!;;::]`) //匹配标点符号,保存下来。 然后分割字符串 toPun := regPunctuation.FindAllString(s, -1) result := regPunctuation.Split(s, -1) if len(result[len(result)-1]) == 0 { result = result[:len(result)-1] } //去掉前后空格,去掉引号 for i := range result { result[i] = strings.TrimSpace(result[i]) regQuoting := regexp.MustCompile("[“”‘’']") result[i] = regQuoting.ReplaceAllString(result[i], "") } return result, toPun }