zoukankan      html  css  js  c++  java
  • Java正则表达式


    1. 不包含thumb.jpg,但包含_HH_,并以.jpg结尾

    public static void testMatch3() {
        // https://www.runoob.com/java/java-regular-expressions.html
        String content1 = "GF3_KAS_FSII_021168_E105.2_N32.5_20200817_L1A_HH_L10004997197.jpg";
        String content2 = "GF3_KAS_FSII_021168_E105.2_N32.5_20200817_L1A_HH_L10004997197.thumb.jpg";
        //
        String content3 = "GF3_KAS_FSII_021168_E105.2_N32.5_20200817_L1A_HV_L10004997197.jpg";
        String content4 = "GF3_KAS_FSII_021168_E105.2_N32.5_20200817_L1A_HV_L10004997197.thumb.jpg";
        // ^.*-mss2.jpg$;^.*-pan2.jpg$
        String pattern = "^((?!thumb).)*_HH_*((?!thumb).)*(.jpg$)"; // "^((?!thumb).)*$"; // ^(?!.*?robots).*$
        boolean isMatch1 = Pattern.matches(pattern, content1); // true
        boolean isMatch2 = Pattern.matches(pattern, content2); // false
        boolean isMatch3 = Pattern.matches(pattern, content3); // true
        boolean isMatch4 = Pattern.matches(pattern, content4); // false
        System.out.println(
            "---------testMatch3-------是否包含了字符串:   " + isMatch1 + " | " + isMatch2 + " | " + isMatch3 + " | " + isMatch4);
      }


    2. 不包含_Check.xml,但以.xml结尾

    public static void testMatch4() {
        // https://www.runoob.com/java/java-regular-expressions.html
        String content1 = "GF5_AHSI_E105.64_N32.80_20200117_009006_L10000071673.xml";
        String content2 = "GF5_AHSI_E105.64_N32.80_20200117_009006_L10000071673_Check.xml";
        // ^.*-mss2.jpg$;^.*-pan2.jpg$
        String pattern = "^((?!_Check).)*(.xml$)"; // "^((?!thumb).)*$"; // ^(?!.*?robots).*$
        boolean isMatch1 = Pattern.matches(pattern, content1); // true
        boolean isMatch2 = Pattern.matches(pattern, content2); // false
        System.out.println(
            "---------testMatch3-------是否包含了字符串:   " + isMatch1 + " | " + isMatch2 );
      }


    -----------------------

  • 相关阅读:
    HDU 5794
    HDU 5794
    3070 Fibonacci 矩阵快速幂
    数论基础
    hdu 1061 Rightmost Digit 快速幂
    poj 2305 Basic remains java
    poj 1001 Exponentiation
    hdu 2054 A == B ? (java)
    java大数练习
    hdu3018 Ant Trip 欧拉回路
  • 原文地址:https://www.cnblogs.com/gispathfinder/p/15457639.html
Copyright © 2011-2022 走看看