parseStrPlus static method
Implementation
static List<String> parseStrPlus(String? string,{RegExp? reg}) {
if (StringUtils.isEmpty(string)) {
return [];
}
RegExp regExp = reg?? RegExp(r'[\u4e00-\u9fa5]' + // 单个中文字符
r'|[a-zA-Z]+' + // 连续英文单词
r'|\d+' + // 连续数字
r'|[,。,.]' // 标点符号,这里加上逗号句号(可扩展)
);
// 使用allMatches
Iterable<RegExpMatch> matches = regExp.allMatches(string!);
List<String> result = [];
for (var m in matches) {
String matchStr = m.group(0)!;
// 对连续英文单词再拆词或处理空格(因为英文短语中间有空格)
if (RegExp(r'^[a-zA-Z]+$').hasMatch(matchStr)) {
// 直接作为一个完整英文单词加入
result.add(matchStr);
} else {
result.add(matchStr);
}
}
return result;
}