| 
/*
 * Output:
 Matches
 
 No Match
 
 * */
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class MainClass {
 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");
 
 System.out.println();
 
 mat = pat.matcher("Java 2");
 
 found = mat.matches();
 
 if (found)
 System.out.println("Matches");
 else
 System.out.println("No Match");
 }
 }
 
 
 
 |