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 );
      }


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

  • 相关阅读:
    [CF1042F]Leaf Sets
    [CF1051F]The Shortest Statement
    [洛谷P1792][国家集训队]种树
    [CF484E]Sign on Fence
    [洛谷P2216][HAOI2007]理想的正方形
    [洛谷P4389]付公主的背包
    [洛谷P4726]【模板】多项式指数函数
    服务器上Ubuntu系统安装
    删除ubuntu系统
    Win10下安装Ubuntu16.04双系统
  • 原文地址:https://www.cnblogs.com/gispathfinder/p/15457639.html
Copyright © 2011-2022 走看看