All Packages Class Hierarchy This Package Previous Next Index
Class gnu.rex.Rex
java.lang.Object
|
+----gnu.rex.Rex
- public class Rex
- extends Object
This is a key class of the package. It allows you to invoke the tow
main actions: expression parsing and matching it against a string.
The regular expressions supported are a subset of lex plus some
extensions:
x the character x.
"x" an x, even if x is an operator.
\x an x, even if x is an operator.
[xy] the character x or y.
[x-z] the character x, y or z.
[^x] any character but x.
. any character but newline.
^x an x at the beginning of a line.
x$ an x at the end of a line.
x? an optional x.
x* 0 or more instances of x.
x+ 1 or more instances of x.
x\|y an x or a y.
\(x\) an x matched as a subexpression.
x{m,n} m through n occurences of x.
\n a back reference, where n is a digit 0 through 9
-
build(String)
- builds an internal representation for a given regular expression and
returns the corresponding reg.expr.
-
config_Alternative(String)
- determines the string recognized as the alternative symbol
-
config_CharClass(String, char)
- defines a new class of characters.
There are at least two default classes \W and \S.
-
config_GroupBraces(String, String)
- determines what sequences stand for the open/close subexpression symbols.
-
match(char[], int, int)
- tries to match the regular expression in a given array of characters
-
printStates()
-
-
toString()
-
build
public static Rex build(String regExpr) throws RegExprSyntaxException
- builds an internal representation for a given regular expression and
returns the corresponding reg.expr. matcher object.
- Parameters:
- regExpr - a string determining a valid regular expression
- Returns:
- a regular expression object to use for reg.expr. matching
- Throws: RegExprSyntaxException
- if regExpr has unacceptable syntax
config_Alternative
public static final void config_Alternative(String alt)
- determines the string recognized as the alternative symbol
- Parameters:
- alt - the default value is "\|"
config_GroupBraces
public static void config_GroupBraces(String openGroup,
String closeGroup)
- determines what sequences stand for the open/close subexpression symbols.
Note that the changes made by a call of this method affect all subsequent
calls of build().
- Parameters:
- openGroup - the default value is "\("
- closeGroup - the default value is "\)"
config_CharClass
public static boolean config_CharClass(String set,
char name)
- defines a new class of characters.
There are at least two default classes \W and \S.
\W stands for the word constituent character class and \S,
which is basically complimentary to \W, defines spaces and delimiters.
- Parameters:
- set - a sequence of characters to comprise the class.
If it begins with a ^ it is interpreted as "all characters but"
(see [^x-z] above ).
- name - a one character name for the class. Only upper case names
are supported in this version.
match
public RexResult match(char input[],
int offset,
int limit)
- tries to match the regular expression in a given array of characters
- Parameters:
- input - input array of characters
- offset - the starting offset
- limit - the ending offset
- Returns:
- the set of pairs each representing offset and length of
the corresponding subexpression. Only 9 (1 through 9) subexpressions
are supported. The pair at 0 element represents the entire matched
region.
printStates
public void printStates()
toString
public String toString()
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index