The AwkCompiler class is used to create compiled regular expressions
conforming to the Awk regular expression syntax. It generates
AwkPattern instances upon compilation to be used in conjunction
with an AwkMatcher instance. AwkMatcher finds true leftmost-longest
matches, so you must take care with how you formulate your regular
expression to avoid matching more than you really want.
The supported regular expression syntax is a superset of traditional AWK,
but NOT to be confused with GNU AWK or other AWK variants. Additionally,
this AWK implementation is DFA-based and only supports 8-bit ASCII.
Consequently, these classes can perform very fast pattern matches in
most cases.
This is the traditional Awk syntax that is supported:
Alternatives separated by |
Quantified atoms
*
Match 0 or more times.
+
Match 1 or more times.
?
Match 0 or 1 times.
Atoms
regular expression within parentheses
a . matches everything including newline
a ^ is a null token matching the beginning of a string
but has no relation to newlines (and is only valid at the
beginning of a regex; this differs from traditional awk
for the sake of efficiency in Java).
a $ is a null token matching the end of a string but has
no relation to newlines (and is only valid at the
end of a regex; this differs from traditional awk for the
sake of efficiency in Java).
Character classes (e.g., [abcd]) and ranges (e.g. [a-z])
Special backslashed characters work within a character class
MULTILINE_MASK
A mask passed as an option to the compile methods
to indicate a compiled regular expression should treat input as having
multiple lines.
compile(char[] pattern,
int options)
Compiles an Awk regular expression into an AwkPattern instance that
can be used by an AwkMatcher object to perform pattern matching.
compile(java.lang.String pattern,
int options)
Compiles an Awk regular expression into an AwkPattern instance that
can be used by an AwkMatcher object to perform pattern matching.
The default mask for the compile methods.
It is equal to 0 and indicates no special options are active.
CASE_INSENSITIVE_MASK
public static final int CASE_INSENSITIVE_MASK
A mask passed as an option to the compile methods
to indicate a compiled regular expression should be case insensitive.
MULTILINE_MASK
public static final int MULTILINE_MASK
A mask passed as an option to the compile methods
to indicate a compiled regular expression should treat input as having
multiple lines. This option affects the interpretation of
the . metacharacters. When this mask is used,
the . metacharacter will not match newlines. The default
behavior is for . to match newlines.
options - A set of flags giving the compiler instructions on
how to treat the regular expression. Currently the
only meaningful flag is AwkCompiler.CASE_INSENSITIVE_MASK.
Returns:
A Pattern instance constituting the compiled regular expression.
This instance will always be an AwkPattern and can be reliably
be casted to an AwkPattern.
options - A set of flags giving the compiler instructions on
how to treat the regular expression. Currently the
only meaningful flag is AwkCompiler.CASE_INSENSITIVE_MASK.
Returns:
A Pattern instance constituting the compiled regular expression.
This instance will always be an AwkPattern and can be reliably
be casted to an AwkPattern.
A Pattern instance constituting the compiled regular expression.
This instance will always be an AwkPattern and can be reliably
be casted to an AwkPattern.
A Pattern instance constituting the compiled regular expression.
This instance will always be an AwkPattern and can be reliably
be casted to an AwkPattern.