去除文章内容的手机号码

package cn.com.test;

import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternCompiler;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.PatternMatcherInput;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;

public class replacePhone {

 public static void main(String[] args) {
  // 手机号码判断
  String htmlContent = "abcdefghigklmnopqrstuvwxyz13666666666adsfhalksabcdefghigklmnopqrstuvwxyzdddddda13666666666";
  String patternStrs = "13\\d{9}";

  replaceMobileTelephone(patternStrs, htmlContent);
 }

 public static String replaceMobileTelephone(String rule, String content) {

  try {
   PatternCompiler complier = new Perl5Compiler();

   PatternMatcher matcher = new Perl5Matcher();

   Pattern patternForLink = complier.compile(rule, Perl5Compiler.CASE_INSENSITIVE_MASK);

   PatternMatcherInput input = new PatternMatcherInput(content);

   while (matcher.contains(input, patternForLink)) {

    content = content.replace(matcher.getMatch().toString(), "***");
   }

  } catch (Exception e) {

   e.printStackTrace();
  }
  return content;
 }
}

下面是用到的jar包。

 

真是晕呀!java有自带的呀!

弄了半小时弄出来了,在看replaceAll这个函数,也不知道自己在弄什么呀!

哈哈。。。

 

代码如下:“文档内容”.replaceAll("正则表达式","要替换成什么");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值