|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.oro.text.regex.Perl5MatchResult
A class used to store and access the results of a Perl5Pattern match.
PatternMatcher
,
Perl5Matcher
Field Summary | |
(package private) int[] |
_beginGroupOffset
Arrays containing the beginning and end offsets of the pattern groups matched within the actual matched pattern contained in the variable match . |
(package private) int[] |
_endGroupOffset
Arrays containing the beginning and end offsets of the pattern groups matched within the actual matched pattern contained in the variable match . |
(package private) String |
_match
The entire string that matched the pattern. |
(package private) int |
_matchBeginOffset
The character offset into the line or stream where the match begins. |
Constructor Summary | |
(package private) |
Perl5MatchResult(int groups)
Constructs a MatchResult able to store match information for a number of subpattern groups. |
Method Summary | |
int |
begin(int group)
Enabled: @param group The pattern subgroup. |
int |
beginOffset(int group)
Returns an offset marking the beginning of the pattern match relative to the beginning of the input. |
int |
end(int group)
Enabled: @param group The pattern subgroup. |
int |
endOffset(int group)
Returns an offset marking the end of the pattern match relative to the beginning of the input. |
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()
The same as group(0). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
int _matchBeginOffset
int[] _beginGroupOffset
match
.
Pattern matching methods that do not match subgroups, will only contain
entries for group 0, which always refers to the entire pattern.
beginGroupOffset
contains the start offset of the groups,
indexed by group number, which will always be 0 for group 0.
endGroupOffset
contains the ending offset + 1 of the groups.
A group matching the null string will have beginGroupOffset
and endGroupOffset
entries of equal value. Following a
convention established by the GNU regular expression library for the
C language, groups that are not part of a match contain -1 as their
begin and end offsets.
int[] _endGroupOffset
match
.
Pattern matching methods that do not match subgroups, will only contain
entries for group 0, which always refers to the entire pattern.
beginGroupOffset
contains the start offset of the groups,
indexed by group number, which will always be 0 for group 0.
endGroupOffset
contains the ending offset + 1 of the groups.
A group matching the null string will have beginGroupOffset
and endGroupOffset
entries of equal value. Following a
convention established by the GNU regular expression library for the
C language, groups that are not part of a match contain -1 as their
begin and end offsets.
String _match
Constructor Detail |
Perl5MatchResult(int groups)
groups
- The number of groups this MatchResult can store.
Only postitive values greater than or equal to 1 make any
sense. At minimum, a MatchResult stores one group which
represents the entire pattern matched including all subparts.Method Detail |
public int length()
MatchResult
MatchResult.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();
length
in interface MatchResult
public int groups()
MatchResult
groups
in interface MatchResult
public String group(int group)
MatchResult
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.
group
in interface MatchResult
group
- The pattern subgroup to return.
public int begin(int group)
MatchResult
begin
in interface MatchResult
group
- The pattern subgroup.
public int end(int group)
MatchResult
end
in interface MatchResult
group
- The pattern subgroup.
public int beginOffset(int group)
beginOffset
in interface MatchResult
group
- The pattern subgroup.
public int endOffset(int group)
endOffset
in interface MatchResult
group
- The pattern subgroup.
public String toString()
toString
in interface MatchResult
toString
in class Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |