Java - Regular Expressions
PatternSyntaxException
A _________ object is an unchecked exception that indicates a syntax error in a regular expression pattern.
Matcher Class
- A Matcher object is the engine that interprets the pattern and performs match operations against an input string. - defines no public constructors. - You obtain a Matcher object by invoking the matcher() method on a Pattern object.
A regular expression
- a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. - They can be used to search, edit, or manipulate text and data.
Capturing Groups
- are a way to treat multiple characters as a single unit. - They are created by placing the characters to be grouped inside a set of parentheses. ((A)(B(C))) there are four such groups − (A)(B(C))) (A) (B(C)) (C)
Pattern Class
- is a compiled representation of a regular expression - provides no public constructors - To create a pattern, you must first invoke one of its public static compile() methods, which will then return a Pattern object. - These methods accept a regular expression as the first argument.
Regular Expressions
- java.util.regex package - are very similar to the Perl programming language and very easy to learn.
java.util.regex package primarily consists of the following 3 classes
Pattern Class Matcher Class PatternSyntaxException
groupCount method on a matcher object
To find out how many groups are present in the expression - returns an int showing the number of capturing groups present in the matcher's pattern. -a special group, group 0, which always represents the entire expression / not included in the total reported by groupCount.