Pattern.CASE_INSENSITIVE : Pattern « java.util.regex « Java by API






Pattern.CASE_INSENSITIVE

/*
IGNORE_CASE match true
MATCH_NORMAL match was false
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainClass {
  public static void main(String[] argv) {
    String pattern = "^q[^u]\\d+\\.";
    String input = "QA777. is the next flight.";

    Pattern reCaseInsens = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
    Pattern reCaseSens = Pattern.compile(pattern);

    boolean found;
    Matcher m;
    m = reCaseInsens.matcher(input); // will match any case
    found = m.lookingAt();           // will match any case
    System.out.println("IGNORE_CASE match " + found);

    m = reCaseSens.matcher(input); // Get matcher w/o case-insens flag
    found = m.lookingAt();         // will match case-sensitively
    System.out.println("MATCH_NORMAL match was " + found);

  }
}

           
       








Related examples in the same category

1.Pattern.CANON_EQ
2.Pattern: compile('d.*ian')
3.Pattern: compile('(\\w+)\\s(\\d+)')
4.Pattern: compile('e.+?d')
5.Pattern: compile('[a-z]+')
6.Pattern: compile(String text)
7.Pattern: matcher(String text)
8.Pattern: split(String str)