Class RegexMatch


  • public final class RegexMatch
    extends Object
    Input subsequence captured by the given group during the previous match operation. See java.util.regex.Matcher.

    Example of use:

     Pattern p = Pattern.compile(regexp);
     Matcher matcher = p.matcher(string);
     if (matcher.matches()) {
         RegexMatch[] match = RegexMatch.getAll(matcher);
         for (int j = 0; j < match.length; ++j) {
              System.out.println("\t$" + j + "='" + match[j].text + "'");
         }
     }
    • Field Detail

      • startIndex

        public final int startIndex
        Index of the start of the input subsequence.
      • endIndex

        public final int endIndex
        Index of the end of the input subsequence.
      • text

        public final String text
        Text contained in the input subsequence.
    • Constructor Detail

      • RegexMatch

        public RegexMatch​(int startIndex,
                          int endIndex,
                          String text)
        Constructor.
        Parameters:
        startIndex - index of the start of the input subsequence
        endIndex - index of the end of the input subsequence
        text - text contained in the input subsequence
    • Method Detail

      • getAll

        public static RegexMatch[] getAll​(Matcher matcher)
        Returns all input subsequence captured during last match operation performed by specified matcher.

        Returned array is empty if matcher has never been used or if input sequence does not match pattern.