How Are Regular Expressions Represented?
by, 04-26-2012 at 06:45 PM (219 Views)
Package java.util.regex has three classes: PatternSyntaxException, Matcher and Pattern.
- Pattern object is basically the compiled presentation of regular expression. For pattern creation first thing is invoking public static methods of compilation that will make pattern object to be returned. Regular expression is accepted by these methods being 1st argument; 1st trial lessons will let you know regarding the required syntax.
- Matcher object is considered to be an engine which will be interpreting patterns. Also, match operations are being performed for input string. Matcher doesn’t define any public constructors. Matcher object is obtained when matcher method is invoked at pattern object.
- PatternSyntaxException is basically unchecked kind of exception which shows sytax errors present in regular expression.
Few last trial lessons explore out all classes in detail. However, first of all one shall understand that how to construct the regular expressions. Hence simpler test harness will be introduced in next section which will repeatedly be used for their syntax exploring.