Class JRegexIterator

java.lang.Object
net.sf.saxon.regex.JRegexIterator
All Implemented Interfaces:
Closeable, AutoCloseable, LastPositionFinder, SequenceIterator, RegexIterator

public class JRegexIterator extends Object implements RegexIterator, LastPositionFinder
Class JRegexIterator - provides an iterator over matched and unmatched substrings. This implementation of RegexIterator uses the JDK regular expression engine.
  • Constructor Details

    • JRegexIterator

      public JRegexIterator(String str, Pattern pattern)
      Construct a RegexIterator. Note that the underlying matcher.find() method is called once to obtain each matching substring. But the iterator also returns non-matching substrings if these appear between the matching substrings.
      Parameters:
      str - the string to be analysed
      pattern - the regular expression
  • Method Details

    • supportsGetLength

      public boolean supportsGetLength()
      Description copied from interface: LastPositionFinder
      Ask whether this iterator supports use of the LastPositionFinder.getLength() method. This method should always be called before calling LastPositionFinder.getLength(), because an iterator that implements this interface may support use of LastPositionFinder.getLength() in some situations and not in others
      Specified by:
      supportsGetLength in interface LastPositionFinder
      Returns:
      true if the LastPositionFinder.getLength() method can be called to determine the length of the underlying sequence.
    • getLength

      public int getLength()
      Description copied from interface: LastPositionFinder
      Get the last position (that is, the number of items in the sequence). This method is non-destructive: it does not change the state of the iterator. The result is undefined if the next() method of the iterator has already returned null. This method must not be called unless the LastPositionFinder.supportsGetLength() has been called and has returned true.
      Specified by:
      getLength in interface LastPositionFinder
      Returns:
      the number of items in the sequence
    • next

      public StringValue next()
      Get the next item in the sequence
      Specified by:
      next in interface RegexIterator
      Specified by:
      next in interface SequenceIterator
      Returns:
      the next item in the sequence
    • isMatching

      public boolean isMatching()
      Determine whether the current item is a matching item or a non-matching item
      Specified by:
      isMatching in interface RegexIterator
      Returns:
      true if the current item (the one most recently returned by next()) is an item that matches the regular expression, or false if it is an item that does not match
    • getRegexGroup

      public UnicodeString getRegexGroup(int number)
      Get a substring that matches a parenthesised group within the regular expression
      Specified by:
      getRegexGroup in interface RegexIterator
      Parameters:
      number - the number of the group to be obtained
      Returns:
      the substring of the current item that matches the n'th parenthesized group within the regular expression
    • getNumberOfGroups

      public int getNumberOfGroups()
      Get the number of captured groups
      Specified by:
      getNumberOfGroups in interface RegexIterator
    • processMatchingSubstring

      public void processMatchingSubstring(RegexMatchHandler action) throws XPathException
      Process a matching substring, performing specified actions at the start and end of each captured subgroup. This method will always be called when operating in "push" mode; it writes its result to context.getReceiver(). The matching substring text is all written to the receiver, interspersed with calls to the methods onGroupStart() and onGroupEnd().
      Specified by:
      processMatchingSubstring in interface RegexIterator
      Parameters:
      action - defines the processing to be performed at the start and end of a group
      Throws:
      XPathException