格式化手机号码为3 3 5
String mobile = "13123456789"; String regex = "(\\d{3})(\\d{3})(\\d{5})"; String formatedMobile = mobile.replaceAll(regex, "$1 $2 $3"); System.out.println(formatedMobile); // 131 234 56789
格式化银行卡号为4 4 4 剩余
String bankCard = "6225880112345678"; String regex = "(\\d{4})(\\d{4})(\\d{4})(\\d{1})"; String formatedBankCard = bankCard.replaceAll(regex, "$1 $2 $3 $4"); System.out.println(formatedBankCard); // 6225 8801 1234 5678
标签:regex,JAVA,手机号,银行卡,bankCard,System,格式化,String From: https://www.cnblogs.com/shichq/p/16935270.html