Matcher: matches() : Matcher « java.util.regex « Java by API






Matcher: matches()

/*
 * 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");
  }
}

           
       








Related examples in the same category

1.Matcher: appendReplacement(StringBuffer sb,String replacement)
2.Matcher.appendTail(StringBuffer sb)
3.Matcher: find()
4.Matcher: group()
5.Matcher: group(int group)
6.Matcher: groupCount()
7.Matcher: lookingAt()
8.Matcher: replaceAll(String text)
9.Matcher: start()