集册 Java实例教程 检查输入字符串是否与正则表达式匹配

检查输入字符串是否与正则表达式匹配

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

556
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
检查输入字符串是否与正则表达式匹配


//package com.nowjava;
/** 
 来自 N o w  J a v a  .   c o m**/


import java.util.regex.Pattern;


public class Main {

    public static void main(String[] argv) {

        String input = "nowjava.com";

        String regex = "nowjava.com";

        System.out.println(isMatching(input, regex));

    }

    public static boolean isMatching(String input, String regex) {

        return Pattern.compile(regex, Pattern.CANON_EQ).matcher(input)

                .matches();

    }

}