过滤非法字符

来源:互联网 发布:本子作者知乎 编辑:程序博客网 时间:2024/05/01 18:15

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public String pipei(String fz,String cl) throws Exception {
  Pattern p = null;
  Matcher m = null;
  boolean b;

  String s = null;

  StringBuffer sb = null;

  int i = 0;
  p = Pattern.compile(fz);
  m = p.matcher(cl);
  b = m.matches();
  sb = new StringBuffer();
      while (m.find()) {
   m.appendReplacement(sb, "***");
   i++;
   }
  m.appendTail(sb);


  return sb.toString();

 }