Method - boolean matches(String regex)

This method attempts to match a given regular expression against the complete subject String and returns true/false, indicating whether the match is successful or not. The following are a few important points to note:

  • Regular expression is applied against the entire String; there is no partial matching
  • Regular expression does not need to be anchored using ^ and $, since it is matched against the entire input
  • The equivalent of Pattern.matches(String regex, CharSequenceinput) method (will be covered later)

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.