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