首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

除了文章内容的手机号码

2012-11-01 
去除文章内容的手机号码package cn.com.testimport org.apache.oro.text.regex.Patternimport org.apach

去除文章内容的手机号码

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("正则表达式","要替换成什么");

热点排行