关键正则表达式:
代码语言:javascript复制ok, _ := regexp.MatchString("^[A-Za-z\du4e00-u9fa5] (,[A-Za-z\du4e00-u9fa5] )*$", text)
源代码:
代码语言:javascript复制func MatchIds(text string) ([]int64, []string) {
int64Ids := make([]int64, 0)
stringIds := make([]string, 0)
// 把可能的分隔符,统一替换成英文 逗号 ,
text = strings.ReplaceAll(text, ",", ",")
text = strings.ReplaceAll(text, "/", ",")
text = strings.ReplaceAll(text, "n", ",")
text = strings.ReplaceAll(text, " ", ",")
fmt.Println("text=", text)
// 支持数字,字母,中文
ok, _ := regexp.MatchString("^[A-Za-z\du4e00-u9fa5] (,[A-Za-z\du4e00-u9fa5] )*$", text)
if ok {
ids := strings.Split(text, ",")
int64Ids = convert.ToInt64Slice(ids)
if len(int64Ids) == 0 {
stringIds = convert.ToStringSlice(ids)
}
}
return int64Ids, stringIds
}