All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class gnu.regexp.REMatch

java.lang.Object
   |
   +----gnu.regexp.REMatch

public class REMatch
extends Object
implements Serializable

Method Index

 o getEndIndex()
Returns the index within the input string where the match in its entirety ends.
 o getStartIndex()
Returns the index within the input string where the match in its entirety begins.
 o getSubEndIndex(int)
Returns the index within the input string used to generate this match where subexpression number sub ends, or -1 if the subexpression does not exist.
 o getSubStartIndex(int)
Returns the index within the input string used to generate this match where subexpression number sub begins, or -1 if the subexpression does not exist.
 o substituteInto(String)
Substitute the results of this match to create a new string.
 o toString()
Returns the string (a substring of the input string used to generate this match) matching the pattern.

Methods

 o toString
 public String toString()
Returns the string (a substring of the input string used to generate this match) matching the pattern. This makes it convenient to write code like the following:

REMatch myMatch = myExpression.getMatch(myString);
if (myMatch != null) System.out.println("Regexp found: "+myMatch);

Overrides:
toString in class Object
 o getStartIndex
 public int getStartIndex()
Returns the index within the input string where the match in its entirety begins.

 o getSubStartIndex
 public int getSubStartIndex(int sub)
Returns the index within the input string used to generate this match where subexpression number sub begins, or -1 if the subexpression does not exist.

Parameters:
sub - Subexpression index
 o getEndIndex
 public int getEndIndex()
Returns the index within the input string where the match in its entirety ends. The return value is the next position after the end of the string; therefore, a match created by the following call:

REMatch myMatch = myExpression.getMatch(myString);

can be viewed (given that myMatch is not null) by creating

String theMatch = myString.substring(myMatch.getStartIndex(), myMatch.getEndIndex());

But you can save yourself that work, since the toString() method (above) does exactly that for you.

 o getSubEndIndex
 public int getSubEndIndex(int sub)
Returns the index within the input string used to generate this match where subexpression number sub ends, or -1 if the subexpression does not exist.

Parameters:
sub - Subexpression index
 o substituteInto
 public String substituteInto(String input) throws REException
Substitute the results of this match to create a new string. This is patterned after PERL, so the tokens to watch out for are $0 through $9. $0 matches the full substring matched; $n matches subexpression number n.

Parameters:
input - A string consisting of literals and $n tokens.
Throws: REException
A specified substring index did not exist.

All Packages  Class Hierarchy  This Package  Previous  Next  Index