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();
	}

 需要補充的歡迎隨時指出.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM