集册 Java实例教程 具有多个排除项的正则表达式

具有多个排除项的正则表达式

欢马劈雪     最近更新时间:2020-01-02 10:19:05

443
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
具有多个排除项的正则表达式



/*
n o w j a v a . c o m - 时  代  Java 提供
*/

import java.util.regex.Pattern;


public class Main

{


  private static String regex = ".*\\.(?!(MDRS_|MDRT_|MDOT_)).*\\..*";


  public static boolean excludeMultiple(String text)

  {

    final boolean matches = Pattern.matches(regex, text);

    System.out.println(text + "=" + matches);

    return matches;

  }


  public static void main(String[] args)

  {

    System.out.println(regex);

    excludeMultiple("XX.MDRS_YY.ZZZZ");
    /*
    来 自*
     时代Java公众号 - nowjava.com
    */

    excludeMulti
展开阅读全文