Use regex patterns to match a string literal exactly - Java Regular Expressions

Java examples for Regular Expressions:Pattern

Description

Use regex patterns to match a string literal exactly

Demo Code

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

public class Main {
  public static void main(String[] args) {
    Pattern pattern = Pattern.compile("abc");
    Matcher matcher = pattern.matcher("abc");
    if (matcher.matches())
      System.out.println("Match.");
    else/*  w  w  w . j  a v a 2s.  c om*/
      System.out.println("Does not match.");
  }

}

Related Tutorials