1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.3 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.4 *5 *6 *7 *8 *9 *10 *11 *12 *13 *14 *15 *16 *17 *18 *19 *20 *21 *22 *23 *24 */
25
26 packagejava.util.regex;27
28 /**
29 * The result of a match operation.30 *31 *
This interface contains query methods used to determine the32 * results of a match against a regular expression. The match boundaries,33 * groups and group boundaries can be seen but not modified through34 * a {@codeMatchResult}.35 *36 *@authorMichael McCloskey37 *@seeMatcher38 *@since1.539 */
40 public interfaceMatchResult {41
42 /**
43 * Returns the start index of the match.44 *45 *@returnThe index of the first character matched46 *47 *@throwsIllegalStateException48 * If no match has yet been attempted,49 * or if the previous match operation failed50 */
51 public intstart();52
53 /**
54 * Returns the start index of the subsequence captured by the given group55 * during this match.56 *57 *
Capturing groups are indexed from left58 * to right, starting at one. Group zero denotes the entire pattern, so59 * the expression m.{@codestart(0)} is equivalent to60 * m.{@codestart()}.
61 *62 *@paramgroup63 * The index of a capturing group in this matcher's pattern64 *65 *@returnThe index of the first character captured by the group,66 * or {@code-1} if the match was successful but the group67 * itself did not match anything68 *69 *@throwsIllegalStateException70 * If no match has yet been attempted,71 * or if the previous match operation failed72 *73 *@throwsIndexOutOfBoundsException74 * If there is no capturing group in the pattern75 * with the given index76 */77 public int start(intgroup);78
79 /**
80 * Returns the offset after the last character matched.81 *82 *@returnThe offset after the last character matched83 *84 *@throwsIllegalStateException85 * If no match has yet been attempted,86 * or if the previous match operation failed87 */
88 public intend();89
90 /**
91 * Returns the offset after the last character of the subsequence92 * captured by the given group during this match.93 *94 *
Capturing groups are indexed from left95 * to right, starting at one. Group zero denotes the entire pattern, so96 * the expression m.{@codeend(0)} is equivalent to97 * m.{@codeend()}.
98 *99 *@paramgroup100 * The index of a capturing group in this matcher's pattern101 *102 *@returnThe offset after the last character captured by the group,103 * or {@code-1} if the match was successful104 * but the group itself did not match anything105 *106 *@throwsIllegalStateException107 * If no match has yet been attempted,108 * or if the previous match operation failed109 *110 *@throwsIndexOutOfBoundsException111 * If there is no capturing group in the pattern112 * with the given index113 */114 public int end(intgroup);115
116 /**
117 * Returns the input subsequence matched by the previous match.118 *119 *
For a matcher m with input sequence s,120 * the expressions m.{@codegroup()} and121 * s.{@codesubstring(}m.{@codestart(),} m.{@codeend())}122 * are equivalent.
123 *124 *Note that some patterns, for example {@codea*}, match the empty125 * string. This method will return the empty string when the pattern126 * successfully matches the empty string in the input.
127 *128 *@returnThe (possibly empty) subsequence matched by the previous match,129 * in string form130 *131 *@throwsIllegalStateException132 * If no match has yet been attempted,133 * or if the previous match operation failed134 */135 publicString group();136
137 /**
138 * Returns the input subsequence captured by the given group during the139 * previous match operation.140 *141 *
For a matcher m, input sequence s, and group index142 * g, the expressions m.{@codegroup(}g{@code)} and143 * s.{@codesubstring(}m.{@codestart(}g{@code
144 * ),} m.{@codeend(}g{@code))}145 * are equivalent.
146 *147 *Capturing groups are indexed from left148 * to right, starting at one. Group zero denotes the entire pattern, so149 * the expression {@codem.group(0)} is equivalent to {@codem.group()}.150 *
151 *152 *If the match was successful but the group specified failed to match153 * any part of the input sequence, then {@codenull} is returned. Note154 * that some groups, for example {@code(a*)}, match the empty string.155 * This method will return the empty string when such a group successfully156 * matches the empty string in the input.
157 *158 *@paramgroup159 * The index of a capturing group in this matcher's pattern160 *161 *@returnThe (possibly empty) subsequence captured by the group162 * during the previous match, or {@codenull} if the group163 * failed to match part of the input164 *165 *@throwsIllegalStateException166 * If no match has yet been attempted,167 * or if the previous match operation failed168 *169 *@throwsIndexOutOfBoundsException170 * If there is no capturing group in the pattern171 * with the given index172 */173 public String group(intgroup);174
175 /**
176 * Returns the number of capturing groups in this match result's pattern.177 *178 *
Group zero denotes the entire pattern by convention. It is not179 * included in this count.180 *181 *
Any non-negative integer smaller than or equal to the value182 * returned by this method is guaranteed to be a valid group index for183 * this matcher.
184 *185 *@returnThe number of capturing groups in this matcher's pattern186 */187 public intgroupCount();188
189 }