Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.regex.Pattern;

public class Main {
    /**
     * Test whether the {@code string} has at least one match by 
     * {@code pattern}.
     * 
     * @param pattern the regexp
     * @param string the string to test
     * 
     * @return true if at least one match, false if no match
     */
    public static boolean test(Pattern pattern, String string) {
        if (pattern == null) {
            throw new NullPointerException("argument 'pattern' cannot be null");
        }
        if (string == null) {
            throw new NullPointerException("argument 'string' cannot be null");
        }
        return pattern.matcher(string).find();
    }
}