Class Match<E>
java.lang.Object
edu.washington.cs.knowitall.regex.Match<E>
- Type Parameters:
E
-
- Direct Known Subclasses:
Match.FinalMatch
,Match.IntermediateMatch
A class to represent a match. Each part of the regular expression is matched
to a sequence of tokens. A match also stores information about the range
of tokens matched and the matching groups in the match.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class
A match representation that has efficient method calls but is immutable.static class
A captured group in a matched expression.protected static final class
A match representation that is mutable but many method calls compute values instead of returning stored values. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(Expression<E> expr, E token, int pos) Convenience method for add(new Group(expr, token, pos)). boolean
add
(Match.Group<E> pair) boolean
addAll
(Collection<Match.Group<E>> pairs) abstract int
endIndex()
Retrieve a group by name.abstract List
<Match.Group<E>> groups()
boolean
isEmpty()
True iff this match contains no pairs.int
length()
List
<Match.Group<E>> pairs()
Pairs differ from the matching groups in that each regular expression element has a pair to associate the element with the text matched.abstract int
tokens()
toString()
-
Field Details
-
pairs
-
-
Constructor Details
-
Match
protected Match() -
Match
-
-
Method Details
-
add
-
addAll
-
add
Convenience method for add(new Group(expr, token, pos)). - Parameters:
expr
-token
-pos
-- Returns:
-
isEmpty
public boolean isEmpty()True iff this match contains no pairs. This should only happen on an IntermediateMatch that has not had any pairs added to it yet. -
toString
-
toMultilineString
-
startIndex
public abstract int startIndex()- Returns:
- the index of the first token matched (inclusive start).
-
endIndex
public abstract int endIndex()- Returns:
- the index one past of the last token matched (exclusive end).
-
pairs
Pairs differ from the matching groups in that each regular expression element has a pair to associate the element with the text matched. For example, 'a*' might be associated with 'a a a a'.- Returns:
- all pairs in this match.
-
groups
- Returns:
- all matching groups (named and unnamed).
-
tokens
- Returns:
- all matched tokens.
-
length
public int length()- Returns:
- the number of tokens in the match.
-
group
Retrieve a group by name.- Parameters:
name
- the name of the group to retrieve.- Returns:
- the associated group.
-