Package gnu.regexp

Class REMatch

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public final class REMatch
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    An instance of this class represents a match completed by a gnu.regexp matching function. It can be used to obtain relevant information about the location of a match or submatch.
    Author:
    Wes Biggs
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int anchor  
      (package private) int eflags  
      (package private) int[] end  
      (package private) int index  
      (package private) REMatch next  
      (package private) int offset  
      (package private) int[] start  
    • Constructor Summary

      Constructors 
      Constructor Description
      REMatch​(int subs, int anchor, int eflags)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      (package private) void assignFrom​(REMatch other)  
      (package private) void clear​(int index)
      Clears the current match and moves the offset to the new index.
      java.lang.Object clone()  
      (package private) void finish​(CharIndexed text)  
      int getEndIndex()
      Returns the index within the input string where the match in its entirety ends.
      int getEndIndex​(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.
      int getStartIndex()
      Returns the index within the input text where the match in its entirety began.
      int getStartIndex​(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.
      int getSubEndIndex​(int sub)
      Deprecated.
      Use getEndIndex(int) instead
      int getSubStartIndex​(int sub)
      Deprecated.
      Use getStartIndex(int) instead.
      java.lang.String substituteInto​(java.lang.String input)
      Substitute the results of this match to create a new string.
      java.lang.String toString()
      Returns the string matching the pattern.
      java.lang.String toString​(int sub)
      Returns the string matching the given subexpression.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • eflags

        int eflags
      • offset

        int offset
      • anchor

        int anchor
      • index

        int index
      • start

        int[] start
      • end

        int[] end
    • Constructor Detail

      • REMatch

        REMatch​(int subs,
                int anchor,
                int eflags)
    • Method Detail

      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • assignFrom

        void assignFrom​(REMatch other)
      • clear

        void clear​(int index)
        Clears the current match and moves the offset to the new index.
      • toString

        public java.lang.String toString()
        Returns the string 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 java.lang.Object
      • getStartIndex

        public int getStartIndex()
        Returns the index within the input text where the match in its entirety began.
      • 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.

      • toString

        public java.lang.String toString​(int sub)
        Returns the string matching the given subexpression. The subexpressions are indexed starting with one, not zero. That is, the subexpression identified by the first set of parentheses in a regular expression could be retrieved from an REMatch by calling match.toString(1).
        Parameters:
        sub - Index of the subexpression.
      • getSubStartIndex

        public int getSubStartIndex​(int sub)
        Deprecated.
        Use getStartIndex(int) instead.
        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. The initial position is zero.
        Parameters:
        sub - Subexpression index
      • getStartIndex

        public int getStartIndex​(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. The initial position is zero.
        Parameters:
        sub - Subexpression index
        Since:
        gnu.regexp 1.1.0
      • getSubEndIndex

        public int getSubEndIndex​(int sub)
        Deprecated.
        Use getEndIndex(int) instead
        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. The initial position is zero.
        Parameters:
        sub - Subexpression index
      • getEndIndex

        public int getEndIndex​(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. The initial position is zero.
        Parameters:
        sub - Subexpression index
      • substituteInto

        public java.lang.String substituteInto​(java.lang.String input)
        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.