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


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

  • 相关阅读:
    nested exception is java.io.FileNotFoundException: class path resource [spring-mybatis.xml] cannot be opened
    jdbc批量插入实现大批量数据快速插入
    setInterval设置停止和循环
    在java中使用dom4j解析xml(示例代码)
    获取请求端的ip地址
    行为型之责任链模式
    行为型之策略模式
    行为型之命令模式
    行为型之模板方法模式
    结构型之门面模式
  • 原文地址:https://www.cnblogs.com/gispathfinder/p/15457639.html
Copyright © 2011-2022 走看看