加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

简单的正则表达式实现对string内容的过滤

发布时间:2020-12-14 01:45:45 所属栏目:百科 来源:网络整理
导读:*/ public String contentFilter(String detaileContent) { //如果详细内容中包括(完)则删除其后面的内容 if(detaileContent.contains("(完)")||detaileContent.contains("(完)")) { int index=detaileContent.lastIndexOf("(完)"); if(index=0) { detai

*/

public String contentFilter(String detaileContent)

{ //如果详细内容中包括(完)则删除其后面的内容

if(detaileContent.contains("(完)")||detaileContent.contains("(完)"))

{

int index=detaileContent.lastIndexOf("(完)");

if(index>=0)

{

detaileContent=detaileContent.substring(0,index);

}

}

//带[ ]的过滤掉 如

String strRegex="[.*?]";

detaileContent=detaileContent.replaceAll(strRegex,"");

//文章开头以“路透”两字开头的第一句话过滤掉,一般以“路透”开头,“-”结尾

String strReg="路透.*?-";

detaileContent=detaileContent.replaceFirst(strReg,"");

return detaileContent;

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读