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
Java Book
Essential Classes
Matcher:
- Regular Expression Processing
- Normal character
- Wildcard character
- Using Wildcards and Quantifiers
- Greedy behavior
- Working with Classes of Characters
- Using replaceAll( )
- Using split( )
- Matcher: appendReplacement(StringBuffer sb,String replacement)
- Matcher.appendTail(StringBuffer sb)
- Matcher: find()
- Matcher: group()
- Matcher: group(int group)
- Matcher: groupCount()
- Matcher: lookingAt()
- Matcher: matches()
- Matcher: replaceAll(String text)
- Matcher: start()