java生成前区号码_java正则表达式的应用——去掉固定电话号码前面的区号

class Test002 {     public static void main(String[] arguments) {         String src = new String("ab43a2c43d");              System.out.println(src.replace("3", "f"));               //=>ab4fa2c4fd.         System.out.println(src.replaceAll("\\d", "f"));          //=>abffafcffd.         System.out.println(src.replaceAll("a", "f"));            //=>fb43f2c43d.         System.out.println(src.replaceFirst("4", "h"));          //=>abh3a2c43d.         System.out.println(src.replaceFirst("\\d", "f"));         //=>abf3a2c43d         String num = new String("076938816888");         System.out.println(num);                  // 00853,00886,00852 not treated         String regex1 = "^010";         String regex2 = "^02[0-9]{8,9}";      //0207777777, 02988888888         String regex3 = "^0[3-9][0-9]{9,10}"; //03947777777, 076912345678                                                     String regex1f = "010";         String regex2f = "02[0-9]";        //020,021,022,023,024,025,027,028,029         String regex3f = "0[3-9][0-9]{2}"; //0310,0769,0755,0999,...                  if (10 <= num.length() && num.length() <= 12) {                          if (num.matches(regex1)) {                 num = num.replaceFirst(regex1f, "");             } else if (num.matches(regex2)) {                 num = num.replaceFirst(regex2f, "");             } else if (num.matches(regex3)) {                 num = num.replaceFirst(regex3f, "");             }         }                  System.out.println(num);     } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值