The Matcher class
An instance of the Matcher class performs various match operations on a character sequence by interpreting a compiled regular expression represented by an instance of Pattern. This is how we use this class to match a regex:
- We create a matcher instance from a pattern by invoking the pattern's matcher method that requires the input sequence as argument
- The instance of matcher is used to perform three types of match operations using these three methods, each returning a Boolean value (true indicates success):
- matches
- find
- lookingAt
These methods perform the matching in the following manner:
- The
matchesmethod attempts to match the complete input sequence using the matcher's pattern - The
findmethod searches the input sequence for the next substring that matches the pattern - The
lookingAtmethod attempts to match the input sequence using the matcher's pattern at the start position.
Let's list down all the important methods from the Matcher class here:
Method Signature | Description |
boolean... |