Pattern: matcher(String text) : Pattern « java.util.regex « Java by API






Pattern: matcher(String text)

/*
 * 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.Pattern.CANON_EQ
2.Pattern.CASE_INSENSITIVE
3.Pattern: compile('d.*ian')
4.Pattern: compile('(\\w+)\\s(\\d+)')
5.Pattern: compile('e.+?d')
6.Pattern: compile('[a-z]+')
7.Pattern: compile(String text)
8.Pattern: split(String str)