There's no obvious way to find out the number of matching subgroups. Testing regex-group()="" doesn't really work, because a group can be empty even if it exists.
You can probably do it with an extension function, something along the lines of
public static Integer numberOfRegexGroups(XPathContext context) {
   RegexIterator ri = context.getCurrentRegexIterator();
   if (ri = null) return null;
   return new Integer(Aggregate.count(ri.getAnother()));
Let me know if that works.
I'm not sure what you mean by finding out the "regex-group index". There's no concept of a current regex-group.
Michael Kay

From: [] On Behalf Of jeff isenhart
Sent: 04 February 2005 23:53
Subject: [saxon] regex-group question

Is there a way to find out the regex-group index or total at runtime? Here is what I’ve hacked so far…


<xsl:analyze-string select="$input"



        <xsl:variable name="values">

            <!-- I would love to know the total groups and/or the current group index.

(not the same size all the time)

Using a loop for now – be nice if I could use $i.. -->

<!-- Build  a csv string .. -->

            <xsl:for-each select="for $i in (1 to 10)  return $i">

           <xsl:if test="not(string-length(regex-group(.)) = 0)">

                  <xsl:value-of select="regex-group(.)"/><xsl:value-of select="’,’"/>





            <xsl:value-of select="$values"/>





Thanks for any suggestions,