To return the string representation of this pattern.
2. Matcher Class
This object is used to perform match operations for an input string in java, thus interpreting the previously explained patterns.
This too defines no public constructors and can be implemented by invoking a matcher() on any pattern object.
Basic Syntax:
// Create a pattern to be searched Patternpattern=Pattern.compile("geeks");// Search above pattern in "geeksforgeeks.org" Matcherm=pattern.matcher("geeksforgeeks.org");
It is used to test whether the regular expression matches the pattern.
Note: Pattern.matches() checks if the whole text matches with a pattern or not. Other methods are mainly used to find multiple occurrences of pattern in text.
3. PatternSyntaxException class
This object of Regex is used to indicate a syntax error in a regular expression pattern and is an unchecked exception.
To return a multiline string containing description of syntax error and its index, the erroneous regular-expression pattern, and a visual indication of the error index within the pattern.