Class Match<E>

java.lang.Object
edu.washington.cs.knowitall.regex.Match<E>
Type Parameters:
E -
Direct Known Subclasses:
Match.FinalMatch, Match.IntermediateMatch

public abstract class Match<E> extends Object
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.
  • Field Details

  • Constructor Details

    • Match

      protected Match()
    • Match

      protected Match(Match<E> match)
  • Method Details

    • add

      public boolean add(Match.Group<E> pair)
    • addAll

      public boolean addAll(Collection<Match.Group<E>> pairs)
    • add

      public boolean add(Expression<E> expr, E token, int pos)
      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

      public String toString()
      Overrides:
      toString in class Object
    • toMultilineString

      public String 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

      public 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. For example, 'a*' might be associated with 'a a a a'.
      Returns:
      all pairs in this match.
    • groups

      public abstract List<Match.Group<E>> groups()
      Returns:
      all matching groups (named and unnamed).
    • tokens

      public abstract List<E> tokens()
      Returns:
      all matched tokens.
    • length

      public int length()
      Returns:
      the number of tokens in the match.
    • group

      public Match.Group<E> group(String name)
      Retrieve a group by name.
      Parameters:
      name - the name of the group to retrieve.
      Returns:
      the associated group.