阅读背景:

java字符串利用正则表达式分割

来源:互联网 

平时用到,整理的,总感觉缺点什么:

private String getKeywordByContent(String content) {
		StringBuffer sbAllKwyword = new StringBuffer();
		content = content.replaceAll(" ", "");//去掉所有空格
		if(content.length()>10){
			String regex = "[\u4E00-\u9FA5\s\d\w]{10}";
			Pattern p = Pattern.compile(regex);
			Matcher m = p.matcher(content);
			int i=0;
			while (m.find()&&i<10) {
				sbAllKwyword.append(m.group());
				sbAllKwyword.append("^");		
				i++;
			}
			logger.info("sbAllKwyword={}",sbAllKwyword.toString());
			if(sbAllKwyword.length()>1){				
				sbAllKwyword.deleteCharAt(sbAllKwyword.length() - 1);
			}
		}else{
			sbAllKwyword.append(content);
		}
		return sbAllKwyword.toString();
	}
private String getKeywo



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: