public static List<String> split(String str, Pattern separatorPattern, int limit, boolean isTrim, boolean ignoreEmpty){
		if(StrUtil.isEmpty(str)){
			return new ArrayList<String>(0);
		}
		if(limit == 1){
			return addToList(new ArrayList<String>(1), str, isTrim, ignoreEmpty);
		}
		
		if(null == separatorPattern){//分隔符为空时按照空白符切分
			return split(str, limit);
		}
		
		final Matcher matcher = separatorPattern.matcher(str);
		final ArrayList<String> list = new ArrayList<>();
		int len = str.length();
		int start = 0;
		while(matcher.find()){
			addToList(list, str.substring(start, matcher.start()), isTrim, ignoreEmpty);
			start = matcher.end();
			
			//检查是否超出范围（最大允许limit-1个，剩下一个留给末尾字符串）
			if(limit > 0 && list.size() > limit-2){
				break;
			}
		}
		return addToList(list, str.substring(start, len), isTrim, ignoreEmpty);
	}
public static List < String > split ( String str , Pattern separatorPattern , int limit , boolean isTrim , boolean ignoreEmpty ) { if ( StrUtil . isEmpty ( str ) ) { return new ArrayList < String > ( 0 ) ; } if ( limit == 1 ) { return addToList ( new ArrayList < String > ( 1 ) , str , isTrim , ignoreEmpty ) ; } if ( null == separatorPattern ) { return split ( str , limit ) ; } final Matcher matcher = separatorPattern . matcher ( str ) ; final ArrayList < String > list = new ArrayList < > ( ) ; int len = str . length ( ) ; int start = 0 ; while ( matcher . find ( ) ) { addToList ( list , str . substring ( start , matcher . start ( ) ) , isTrim , ignoreEmpty ) ; start = matcher . end ( ) ; if ( limit > 0 && list . size ( ) > limit - 2 ) { break ; } } return addToList ( list , str . substring ( start , len ) , isTrim , ignoreEmpty ) ; }
通过正则切分字符串
@param str 字符串
@param separatorPattern 分隔符正则{@link Pattern}
@param limit 限制分片数
@param isTrim 是否去除切分字符串后每个元素两边的空格
@param ignoreEmpty 是否忽略空串
@return 切分后的集合
@since 3.0.8