首页 > 编程语言 > 详细

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

时间:2018-10-24 11:44:25      阅读:124      评论:0      收藏:0      [点我收藏+]

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

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

 需要补充的欢迎随时指出.

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

原文:https://www.cnblogs.com/xxbai1123/p/9842393.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!