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 matches method attempts to match the complete input sequence using the matcher's pattern
  • The find method searches the input ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.