Class regexp.Regexp
All Packages Class Hierarchy This Package Previous Next Index
Class regexp.Regexp
java.lang.Object
|
+----regexp.Regexp
- public class Regexp
- extends Object
A Regexp is a piece of a regular expression. The system is
designed to be at once flexible and efficient. Therefore, very
little allocation is done while matching a regexp. It's mostly all
done during the compilation stage.
Here's an example of how to use this class:
import starwave.util.regexp.*;
Regexp reg = Regexp.compile("^([a-z]*) ([0-9]*)");
String buffer = readFileIntoString("somefile.text");
Result result;
int pos = 0;
while ((result = reg.searchForward(buffer, pos)) != null) {
System.out.println("Matched " + result.getMatch(1)
+ " and " + result.getMatch(2));
pos = result.matchEnd() + 1;
}
-
compile(String)
-
-
compile(String, boolean)
- Return a compiled regular expression.
-
main(String[])
-
-
match(char[], int, int)
- Returns true if the specified String is matched by this
regular expression.
-
match(State)
- Walks as far as it can down a regular expression, returning
true if it made it all the way to the end, and false otherwise.
-
match(String, int)
- Returns true if the specified String is matched by this
regular expression.
-
searchBackward(char[], int, int)
- Returns true if the specified char array is matched from the
specified offset backward by this regular expression.
-
searchBackward(String, int)
- Returns true if the specified String is matched from the
specified offset backward by this regular expression.
-
searchForward(char[], int, int)
- Returns true if the specified char array is matched anywhere by
this regular expression.
-
searchForward(String, int)
- Returns true if the specified String is matched anywhere by
this regular expression.
-
toString()
-
-
toStringThis()
-
compile
public static Regexp compile(String expr)
compile
public static Regexp compile(String expr,
boolean mapCase)
- Return a compiled regular expression. A compiled expression
consists of a bunch of Regexp subclasses linked together in a
double linked list. The only reason for prev pointers is to
easily handled Multi processing, where you have to splice into
the list sometimes.
match
protected boolean match(State state)
- Walks as far as it can down a regular expression, returning
true if it made it all the way to the end, and false otherwise.
When false, restores state to original state.
match
public Result match(String data,
int offset)
- Returns true if the specified String is matched by this
regular expression. This is not to be confused with search,
which looks all through the string for a match. This just looks
to see if the beginning of the string matches.
- Parameters:
- data - string to match
- Returns:
- a regexp.Result on success, null on failure
- See Also:
- Result
match
public Result match(char data[],
int offset,
int length)
- Returns true if the specified String is matched by this
regular expression. This is not to be confused with search,
which looks all through the string for a match. This just looks
to see if the beginning of the string matches.
- Parameters:
- data - string to match
- Returns:
- a regexp.Result on success, null on failure
- See Also:
- Result
searchForward
public final Result searchForward(String data,
int offset)
- Returns true if the specified String is matched anywhere by
this regular expression. This is not like match, which only
matches at the beginning of the string. This searches through
the whole string starting at the specified offset looking for a
match.
- Parameters:
- data - string to match
- Returns:
- a regexp.Result on success, null on failure
- See Also:
- Result
searchForward
public final Result searchForward(char data[],
int offset,
int length)
- Returns true if the specified char array is matched anywhere by
this regular expression. This is not like match, which only
matches at the beginning of the string. This searches through
the whole string starting at the specified offset looking for a
match.
- Parameters:
- data - string to match
- Returns:
- a regexp.Result on success, null on failure
- See Also:
- Result
searchBackward
public Result searchBackward(String data,
int offset)
- Returns true if the specified String is matched from the
specified offset backward by this regular expression. This is
not like match, which only matches at the beginning of the
string. This searches through the whole string starting at the
specified offset looking for a match.
- Parameters:
- data - string to match
- Returns:
- a regexp.Result on success, null on failure
- See Also:
- Result
searchBackward
public Result searchBackward(char data[],
int offset,
int length)
- Returns true if the specified char array is matched from the
specified offset backward by this regular expression. This is
not like match, which only matches at the beginning of the
string. This searches through the whole string starting at the
specified offset looking for a match.
- Parameters:
- data - string to match
- Returns:
- a regexp.Result on success, null on failure
- See Also:
- Result
main
public static void main(String args[]) throws Exception
toString
public final String toString()
- Overrides:
- toString in class Object
toStringThis
public String toStringThis()
All Packages Class Hierarchy This Package Previous Next Index