Matcher.matches method : Matcher « Regular Expressions « Java Tutorial






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

public class MainClass {
  public static void main(String args[]) {
    Pattern p = Pattern.compile("J2SE");

    String candidateString_1 = "j2se";
    String candidateString_2 = "J2SE ";
    String candidateString_3 = "J2SE";

    Matcher matcher_1 = p.matcher(candidateString_1);
    Matcher matcher_2 = p.matcher(candidateString_2);
    Matcher matcher_3 = p.matcher(candidateString_3);

    String msg = ":" + candidateString_1 + ": matches?: ";
    System.out.println(msg + matcher_1.matches());

    msg = ":" + candidateString_2 + ": matches?: ";
    System.out.println(msg + matcher_2.matches());

    msg = ":" + candidateString_3 + ": matches?: ";
    System.out.println(msg + matcher_3.matches());
  }
}
/*

*/
:j2se: matches?: false
:J2SE : matches?: false
:J2SE: matches?: true








8.4.Matcher
8.4.1.Create a Matcher from Pattern
8.4.2.Matcher.start() method
8.4.3.Matcher.end(int) method
8.4.4.Matcher.LookingAt method
8.4.5.Matcher.matches method
8.4.6.Matcher.pattern method
8.4.7.Matcher.replaceAll method
8.4.8.Matcher.reset(CharSequence) method
8.4.9.Matcher.group() method
8.4.10.Matcher.find method
8.4.11.Matcher.find(int) method
8.4.12.Find the starting point of the first 'Bond'
8.4.13.Demonstrates the usage of the Matcher.reset() method
8.4.14.Matcher.appendReplacement method
8.4.15.REGEX = '\\bdog\\b'
8.4.16.lookingAt vs matches