phone.replaceAll("(\d{3})\d{4}(\d{4})","$1****$2");
152****4799
idCard.replaceAll("(\d{4})\d{10}(\w{4})","$1*****$2");
4304*****7733
$1、$2、……表示正则表达式里面第一个、第二个、……括号里面的匹配内容
转自:http://blog.csdn.net/hekewangzi/article/details/50905098