public static void main(String[] args) {
        // LMEZX1912261505YQ
        final String REGEX_LM_TRACKING_NUMBER = "^LME(ZX|PY)(\\d{10})YQ$";
        final String REGEX_POLAND_POST_TRACKING_NUMBER0 = "^00\\d{1}590077((\\d{11})|(\\d{12}))$";
        final String REGEX_POLAND_POST_TRACKING_NUMBER1 = "^(A|C|E|H|L|R|S|U|V)([A-Z]{1})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})\\s?PL$";
        final String REGEX_POLAND_POST_TRACKING_NUMBER2 = "^P(00|02|03|04)(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{2})";
        // P00 *** *** *** **
        // P02 *** *** *** **
        // P03 *** *** *** **
        // P04 *** *** *** **
        System.out.println("六脉小包:" + isMatch(REGEX_LM_TRACKING_NUMBER, "LMEZX1912261505YQ"));
        System.out.println("波兰邮政:" + isMatch(REGEX_POLAND_POST_TRACKING_NUMBER0, "00559007730404996086"));
        System.out.println("波兰邮政:" + isMatch(REGEX_POLAND_POST_TRACKING_NUMBER1, "CO 191 229 001PL"));
        System.out.println("波兰邮政:" + isMatch(REGEX_POLAND_POST_TRACKING_NUMBER2, "P0412345678910"));
        
        // *** *** *** *** *** *** *** ***
        final String REGEX_POLAND_INPOST_TRACKING_NUMBER1 = "(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})";
        // 4 *** *** *** *** *** *** *** **
        // 5 *** *** *** *** *** *** *** **
        // 6 *** *** *** *** *** *** *** **
        // 9 *** *** *** *** *** *** *** **
        final String REGEX_POLAND_INPOST_TRACKING_NUMBER2 = "^[4|5|6|9](\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{2})$";
        System.out.println("波兰INPOST:" + isMatch(REGEX_POLAND_INPOST_TRACKING_NUMBER1, "520 000 017 831 331 016 463 590"));
        System.out.println("波兰INPOST:" + isMatch(REGEX_POLAND_INPOST_TRACKING_NUMBER2, "920000017831331016463590"));
        // A# *** *** *** LU
        // C# *** *** *** LU
        // E# *** *** *** LU
        // L# *** *** *** LU
        // R# *** *** *** LU
        // S# *** *** *** LU
        // V# *** *** *** LU
        // 18#! *** ***
        // 19#! *** ***
        final String REGEX_LUXEMBOURG_POST_TRACKING_NUMBER1 = "^[A|C|E|L|R|S|V]([A-Z]{1})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})\\s?LU$";
        final String REGEX_LUXEMBOURG_POST_TRACKING_NUMBER2 = "^1[8|9]([A-Z]{1})([A-Z0-9]{1})(\\s?\\d{3})(\\s?\\d{3})$";
        System.out.println("卢森堡邮政:" + isMatch(REGEX_LUXEMBOURG_POST_TRACKING_NUMBER1, "LL329614989 LU"));
        System.out.println("卢森堡邮政:" + isMatch(REGEX_LUXEMBOURG_POST_TRACKING_NUMBER2, "18A9 001 001"));
        // 92 *** *** *** *** *** *** *** ***
        // 420 *** *** *** *** *** *** *** *** ***
        // 420 *** *** *** *** *** *** *** *** *** *** *
        final String REGEX_USPS_TRACKING_NUMBER1 = "^92((\\s?\\d{3}){8})$";
        final String REGEX_USPS_TRACKING_NUMBER2 = "^420((\\s?\\d{3}){9}|(\\s?\\d{3}){10}(\\s?\\d{1}))$";
        System.out.println("USPS:" + isMatch(REGEX_USPS_TRACKING_NUMBER1, "92 748 927 005 359 000 000 151 755"));
        System.out.println("USPS:" + isMatch(REGEX_USPS_TRACKING_NUMBER2, "420 800 119 261 292 700 535 900 000 001 002 5"));//4208001192612927005359000000010025
        // A# *** *** *** CN
        // B# *** *** *** CN
        // C# *** *** *** CN
        // E# *** *** *** CN
        // F# *** *** *** CN
        // L# *** *** *** CN
        // P# *** *** *** CN
        // R# *** *** *** CN
        // S# *** *** *** CN
        // U# *** *** *** CN
        // V# *** *** *** CN
        // 68 *** *** * *** *** *** *
        final String REGEX_CHINA_POST_TRACKING_NUMBER1 = "^[A|B|C|E|F|L|P|R|S|U|V]([A-Z]{1})((\\s?\\d{3}){3})(\\s?)CN$";
        final String REGEX_CHINA_POST_TRACKING_NUMBER2 = "^68((\\s?\\d{3}){2})(\\s?\\d{1})((\\s?\\d{3}){3})(\\s?\\d{1})$";
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER1, "LW372557882CN"));
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER1, "LW 372 557 882CN"));
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER1, "RV231909746CN"));
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER2, "68 000 000 0 000 000 000 0"));
    }
    
    public static boolean isMatch(String regex, String orginal) {
        if (orginal == null || orginal.trim().equals("")) { //$NON-NLS-1$
            return false;
        }
        Pattern pattern = Pattern.compile(regex);
        Matcher isNum = pattern.matcher(orginal);
        return isNum.matches();
    }

 

    public static void main(String[] args) {
        // LMEZX1912261505YQ
        final String REGEX_LM_TRACKING_NUMBER = "^LME(ZX|PY)(\\d{10})YQ$";
        final String REGEX_POLAND_POST_TRACKING_NUMBER0 = "^00\\d{1}590077((\\d{11})|(\\d{12}))$";
        final String REGEX_POLAND_POST_TRACKING_NUMBER1 = "^(A|C|E|H|L|R|S|U|V)([A-Z]{1})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})\\s?PL$";
        final String REGEX_POLAND_POST_TRACKING_NUMBER2 = "^P(00|02|03|04)(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{2})";
        // P00 *** *** *** **
        // P02 *** *** *** **
        // P03 *** *** *** **
        // P04 *** *** *** **
        System.out.println("六脉小包:" + isMatch(REGEX_LM_TRACKING_NUMBER, "LMEZX1912261505YQ"));
        System.out.println("波兰邮政:" + isMatch(REGEX_POLAND_POST_TRACKING_NUMBER0, "00559007730404996086"));
        System.out.println("波兰邮政:" + isMatch(REGEX_POLAND_POST_TRACKING_NUMBER1, "CO 191 229 001PL"));
        System.out.println("波兰邮政:" + isMatch(REGEX_POLAND_POST_TRACKING_NUMBER2, "P0412345678910"));
        
        // *** *** *** *** *** *** *** ***
        final String REGEX_POLAND_INPOST_TRACKING_NUMBER1 = "(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})";
        // 4 *** *** *** *** *** *** *** **
        // 5 *** *** *** *** *** *** *** **
        // 6 *** *** *** *** *** *** *** **
        // 9 *** *** *** *** *** *** *** **
        final String REGEX_POLAND_INPOST_TRACKING_NUMBER2 = "^[4|5|6|9](\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{2})$";
        System.out.println("波兰INPOST:" + isMatch(REGEX_POLAND_INPOST_TRACKING_NUMBER1, "520 000 017 831 331 016 463 590"));
        System.out.println("波兰INPOST:" + isMatch(REGEX_POLAND_INPOST_TRACKING_NUMBER2, "920000017831331016463590"));
        // A# *** *** *** LU
        // C# *** *** *** LU
        // E# *** *** *** LU
        // L# *** *** *** LU
        // R# *** *** *** LU
        // S# *** *** *** LU
        // V# *** *** *** LU
        // 18#! *** ***
        // 19#! *** ***
        final String REGEX_LUXEMBOURG_POST_TRACKING_NUMBER1 = "^[A|C|E|L|R|S|V]([A-Z]{1})(\\s?\\d{3})(\\s?\\d{3})(\\s?\\d{3})\\s?LU$";
        final String REGEX_LUXEMBOURG_POST_TRACKING_NUMBER2 = "^1[8|9]([A-Z]{1})([A-Z0-9]{1})(\\s?\\d{3})(\\s?\\d{3})$";
        System.out.println("卢森堡邮政:" + isMatch(REGEX_LUXEMBOURG_POST_TRACKING_NUMBER1, "LL329614989 LU"));
        System.out.println("卢森堡邮政:" + isMatch(REGEX_LUXEMBOURG_POST_TRACKING_NUMBER2, "18A9 001 001"));
        // 92 *** *** *** *** *** *** *** ***
        // 420 *** *** *** *** *** *** *** *** ***
        // 420 *** *** *** *** *** *** *** *** *** *** *
        final String REGEX_USPS_TRACKING_NUMBER1 = "^92((\\s?\\d{3}){8})$";
        final String REGEX_USPS_TRACKING_NUMBER2 = "^420((\\s?\\d{3}){9}|(\\s?\\d{3}){10}(\\s?\\d{1}))$";
        System.out.println("USPS:" + isMatch(REGEX_USPS_TRACKING_NUMBER1, "92 748 927 005 359 000 000 151 755"));
        System.out.println("USPS:" + isMatch(REGEX_USPS_TRACKING_NUMBER2, "420 800 119 261 292 700 535 900 000 001 002 5"));//4208001192612927005359000000010025
        // A# *** *** *** CN
        // B# *** *** *** CN
        // C# *** *** *** CN
        // E# *** *** *** CN
        // F# *** *** *** CN
        // L# *** *** *** CN
        // P# *** *** *** CN
        // R# *** *** *** CN
        // S# *** *** *** CN
        // U# *** *** *** CN
        // V# *** *** *** CN
        // 68 *** *** * *** *** *** *
        final String REGEX_CHINA_POST_TRACKING_NUMBER1 = "^[A|B|C|E|F|L|P|R|S|U|V]([A-Z]{1})((\\s?\\d{3}){3})(\\s?)CN$";
        final String REGEX_CHINA_POST_TRACKING_NUMBER2 = "^68((\\s?\\d{3}){2})(\\s?\\d{1})((\\s?\\d{3}){3})(\\s?\\d{1})$";
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER1, "LW372557882CN"));
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER1, "LW 372 557 882CN"));
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER1, "RV231909746CN"));
        System.out.println("中国邮政:" + isMatch(REGEX_CHINA_POST_TRACKING_NUMBER2, "68 000 000 0 000 000 000 0"));
    }
    
    public static boolean isMatch(String regex, String orginal) {
        if (orginal == null || orginal.trim().equals("")) { //$NON-NLS-1$
            return false;
        }
        Pattern pattern = Pattern.compile(regex);
        Matcher isNum = pattern.matcher(orginal);
        return isNum.matches();
    }

posted on 2019-12-27 18:02  明湖樵夫  阅读(305)  评论(0编辑  收藏  举报