The PatternCompiler interface defines the operations a regular
expression compiler must implement. However, the types of
regular expressions recognized by a compiler and the Pattern
implementations produced as a result of compilation are not
restricted.
A PatternCompiler instance is used to compile the string representation
(either as a String or char[]) of a regular expression into a Pattern
instance. The Pattern can then be used in conjunction with the appropriate
PatternMatcher instance to perform pattern searches. A form
of use might be:
PatternCompiler compiler;
PatternMatcher matcher;
Pattern pattern;
String input;
// Initialization of compiler, matcher, and input omitted;
try {
pattern = compiler.compile("\\d+");
} catch(MalformedPatternException e) {
System.out.println("Bad pattern.");
System.out.println(e.getMessage());
System.exit(1);
}
if(matcher.matches(input, pattern))
System.out.println(input + " is a number");
else
System.out.println(input + " is not a number");
Specific PatternCompiler implementations such as Perl5Compiler may have
variations of the compile() methods that take extra options affecting
the compilation of a pattern. However, the PatternCompiler method
implementations should provide the default behavior of the class.
version: @version@ since: 1.0 See Also: Pattern See Also: PatternMatcher See Also: MalformedPatternException |