Hi,

  I try to use the new Regex package in Saxon 9.5.  But I don't really
understand the iterator model used by RegularExpression.analyze().
What I would like to achieve, is to match a value against an XPath
regex, and then get all the pieces from the matched value, based on
the groups in the regex.  For each "piece", I need the info "am I part
of a group?" and if yes, which one.  For instance:

    Regex: /foo/([a-z]+)/([0-9]+)
    Value: /foo/bar/1234

  Expected result:

    Piece: /foo/ (no group)
    Piece: bar   (group #1)
    Piece: /     (no group)
    Piece: 1234   (group #2)

  What I tried so far:

    public static void main(String[] args)
            throws Exception
    {
        loop("/foo/bar/1234", "/foo/([a-z]+)/([0-9]+)");
    }

    private static void loop(String value, String lexical)
            throws Exception
    {
        RegularExpression regex =
            new ARegularExpression(lexical, "", "XP30", null);
        RegexIterator it = regex.analyze(value);

        StringValue s1;
        while ( (s1 = (StringValue) it.next()) != null ) {
            System.out.println("Value: " + s1);
            SequenceIterator groups = it.getRegexGroupIterator();

            StringValue s2;
            while ( (s2 = (StringValue) groups.next()) != null ) {
                System.out.println("   Item: " + s2);
            }
        }
    }

  This output the following:

    Value: "/foo/bar/1234"
      Item: "bar"
      Item: "1234"

  So the first-level iterator "loops" over the entire string, as a
whole, and the second-level iterator loops over the "grouped values"
only.  But I am not sure how to cut the initial value into pieces
based on groups.

  Is that possible at all?

  Regards,
 
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/