Matcher: lookingAt()

boolean lookingAt()
match the input sequence, starting at the beginning of the region, against the pattern.

/*
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);
  }
}
Home 
  Java Book 
    Essential Classes  

Matcher:
  1. Regular Expression Processing
  2. Normal character
  3. Wildcard character
  4. Using Wildcards and Quantifiers
  5. Greedy behavior
  6. Working with Classes of Characters
  7. Using replaceAll( )
  8. Using split( )
  9. Matcher: appendReplacement(StringBuffer sb,String replacement)
  10. Matcher.appendTail(StringBuffer sb)
  11. Matcher: find()
  12. Matcher: group()
  13. Matcher: group(int group)
  14. Matcher: groupCount()
  15. Matcher: lookingAt()
  16. Matcher: matches()
  17. Matcher: replaceAll(String text)
  18. Matcher: start()