Name
[2.0] regex-group()
When using a regular expression to process a string,
this function returns portions of the analyzed string based on
groups in the regular expression. This function is used inside the
<xsl:matching-substring>
element only.
Syntax
xs:stringregex-group(
xs:integer
)
Inputs
An xs:integer
representing a section of the regular expression.
Output
The portion of the analyzed string that matches the specified portion of the regular expression. A portion of a regular expression must be in parentheses to be considered a group.
Here are some notes about how regex-group()
works:
Calling
regex-group(0)
returns the entire matching substring, including characters that don’t belong to any group.If the requested portion of the regular expression exists, but doesn’t match anything in the analyzed string,
regex-group()
returns a zero-length string. (In other words, the group is optional in the regular expression.)If the requested portion of the regular expression exists, but it matches the zero-length portion of the analyzed string,
regex-group()
returns a zero-length string.If the requested portion of the regular expression doesn’t exist (we call
regex-
group(4)
when the regular expression has only three groups, for example),regex-group()
returns a zero-length string.Finally,
regex-group()
returns a zero-length string if the group number is a negative integer.
Defined in
XSLT 2.0 section 15, “Regular Expressions.”
Example
We’ll use a simplified version of one of the stylesheets we used ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.