RegExpr.java Source code

Java tutorial

Introduction

Here is the source code for RegExpr.java

Source

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class RegExpr {
    public static void main(String args[]) {
        Pattern pat;
        Matcher mat;
        boolean found;

        pat = Pattern.compile("Java");
        mat = pat.matcher("Java");

        found = mat.matches();

        if (found)
            System.out.println("Matches");
        else
            System.out.println("No Match");

        mat = pat.matcher("Java 2");

        found = mat.matches();

        if (found)
            System.out.println("Matches");
        else
            System.out.println("No Match");
    }
}