org.apache.oro.text.regex
public final class Perl5Compiler extends Object implements PatternCompiler
Perl5Compiler and Perl5Matcher are designed with the intent that you use a separate instance of each per thread to avoid the overhead of both synchronization and concurrent access (e.g., a match that takes a long time in one thread will block the progress of another thread with a shorter match). If you want to use a single instance of each in a concurrent program, you must appropriately protect access to the instances with critical sections. If you want to share Perl5Pattern instances between concurrently executing instances of Perl5Matcher, you must compile the patterns with {@link Perl5Compiler#READ_ONLY_MASK}.
Since: 1.0
Version: 2.0.8
See Also: PatternCompiler MalformedPatternException Perl5Pattern Perl5Matcher
Field Summary | |
---|---|
static int | CASE_INSENSITIVE_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate a compiled regular expression should be case insensitive. |
static int | DEFAULT_MASK
The default mask for the {@link #compile compile} methods.
|
static int | EXTENDED_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate a compiled regular expression should be treated as a Perl5
extended pattern (i.e., a pattern using the /x modifier). |
static int | MULTILINE_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate a compiled regular expression should treat input as having
multiple lines. |
static int | READ_ONLY_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate that the resulting Perl5Pattern should be treated as a
read only data structure by Perl5Matcher, making it safe to share
a single Perl5Pattern instance among multiple threads without needing
synchronization. |
static int | SINGLELINE_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate a compiled regular expression should treat input as being
a single line. |
Method Summary | |
---|---|
Pattern | compile(char[] pattern, int options)
Compiles a Perl5 regular expression into a Perl5Pattern instance that
can be used by a Perl5Matcher object to perform pattern matching.
|
Pattern | compile(char[] pattern)
Same as calling compile(pattern, Perl5Compiler.DEFAULT_MASK);
|
Pattern | compile(String pattern)
Same as calling compile(pattern, Perl5Compiler.DEFAULT_MASK);
|
Pattern | compile(String pattern, int options)
Compiles a Perl5 regular expression into a Perl5Pattern instance that
can be used by a Perl5Matcher object to perform pattern matching.
|
static String | quotemeta(char[] expression)
Given a character string, returns a Perl5 expression that interprets
each character of the original string literally. |
static String | quotemeta(String expression)
Given a character string, returns a Perl5 expression that interprets
each character of the original string literally. |
Parameters: pattern A Perl5 regular expression to compile. options A set of flags giving the compiler instructions on
how to treat the regular expression. The flags
are a logical OR of any number of the five MASK
constants. For example:
regex =
compiler.compile(pattern, Perl5Compiler.
CASE_INSENSITIVE_MASK |
Perl5Compiler.MULTILINE_MASK);
This says to compile the pattern so that it treats
input as consisting of multiple lines and to perform
matches in a case insensitive manner.
Returns: A Pattern instance constituting the compiled regular expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Perl5 regular expression.
Parameters: pattern A regular expression to compile.
Returns: A Pattern instance constituting the compiled regular expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Perl5 regular expression.
Parameters: pattern A regular expression to compile.
Returns: A Pattern instance constituting the compiled regular expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Perl5 regular expression.
Parameters: pattern A Perl5 regular expression to compile. options A set of flags giving the compiler instructions on
how to treat the regular expression. The flags
are a logical OR of any number of the five MASK
constants. For example:
regex =
compiler.compile("^\\w+\\d+$",
Perl5Compiler.CASE_INSENSITIVE_MASK |
Perl5Compiler.MULTILINE_MASK);
This says to compile the pattern so that it treats
input as consisting of multiple lines and to perform
matches in a case insensitive manner.
Returns: A Pattern instance constituting the compiled regular expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Perl5 regular expression.
In effect, this method is the analog of the Perl5 quotemeta() builtin method.
Parameters: expression The expression to convert.
Returns: A String containing a Perl5 regular expression corresponding to a literal interpretation of the pattern.
In effect, this method is the analog of the Perl5 quotemeta() builtin method.
Parameters: pattern The pattern to convert.
Returns: A String containing a Perl5 regular expression corresponding to a literal interpretation of the pattern.