org.apache.oro.text.regex
Interface MatchResult

All Known Implementing Classes:
Perl5MatchResult

public interface MatchResult

Untamed:


Method Summary
 int begin(int group)
          Enabled: @param group The pattern subgroup.
 int beginOffset(int group)
          Enabled: Returns an offset marking the beginning of the pattern match relative to the beginning of the input from which the match was extracted.
 int end(int group)
          Enabled: @param group The pattern subgroup.
 int endOffset(int group)
          Enabled: Returns an offset marking the end of the pattern match relative to the beginning of the input from which the match was extracted.
 String group(int group)
          Enabled: Returns the contents of the parenthesized subgroups of a match, counting parentheses from left to right and starting from 1.
 int groups()
          Enabled: @return The number of groups contained in the result.
 int length()
          Enabled: A convenience method returning the length of the entire match.
 String toString()
          Suppressed: Returns the same as group(0).
 

Method Detail

length

public int length()
Enabled: A convenience method returning the length of the entire match. If you want to get the length of a particular subgroup you should use the group(int) method to get the string and then access its length() method as follows:

 int length = -1; // Use -1 to indicate group doesn't exist
 MatchResult result;
 String subgroup;

 // Initialization of result omitted

 subgroup = result.group(1);
 if(subgroup != null)
   length = subgroup.length();

 

The length() method serves as a more a more efficient way to do:

 length = result.group(0).length();
 

Returns:
The length of the match.

groups

public int groups()
Enabled: @return The number of groups contained in the result. This number includes the 0th group. In other words, the result refers to the number of parenthesized subgroups plus the entire match itself.


group

public String group(int group)
Enabled: Returns the contents of the parenthesized subgroups of a match, counting parentheses from left to right and starting from 1. Group 0 always refers to the entire match. For example, if the pattern foo(\d+) is used to extract a match from the input abfoo123 , then group(0) will return foo123 and group(1) will return 123 . group(2) will return null because there is only one subgroup in the original pattern.

Parameters:
group - The pattern subgroup to return.
Returns:
A string containing the indicated pattern subgroup. Group 0 always refers to the entire match. If a group was never matched, it returns null. This is not to be confused with a group matching the null string, which will return a String of length 0.

begin

public int begin(int group)
Enabled: @param group The pattern subgroup.

Returns:
The offset into group 0 of the first token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1. Be aware that a group that matches the null string at the end of a match will have an offset equal to the length of the string, so you shouldn't blindly use the offset to index an array or String.

end

public int end(int group)
Enabled: @param group The pattern subgroup.

Returns:
Returns one plus the offset into group 0 of the last token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1. A group matching the null string will return its start offset.

beginOffset

public int beginOffset(int group)
Enabled: Returns an offset marking the beginning of the pattern match relative to the beginning of the input from which the match was extracted.

Parameters:
group - The pattern subgroup.
Returns:
The offset of the first token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1.

endOffset

public int endOffset(int group)
Enabled: Returns an offset marking the end of the pattern match relative to the beginning of the input from which the match was extracted.

Parameters:
group - The pattern subgroup.
Returns:
Returns one plus the offset of the last token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1. A group matching the null string will return its start offset.

toString

public String toString()
Suppressed: Returns the same as group(0).

Overrides:
toString in class Object
Returns:
A string containing the entire match.


comments?