# EXSLT - regexp:match - Implementer Page

Version: 1 Status: new User Page: index.html XML Definition: regexp.match.xml Function Package: regexp.match.zip #### Function Syntax
    object regexp:match(string, string, string?)
The `regexp:match` function lets you get hold of the substrings of the string passed as the first argument that match the captured parts of the regular expression passed as the second argument. The second argument is a regular expression that follows the Javascript regular expression syntax. The third argument is a string consisting of character flags to be used by the match. If a character is present then that flag is true. The flags are: `g`: global match - the submatches from all the matches in the string are returned. If this character is not present, then only the submatches from the first match in the string are returned. `i`: case insensitive - the regular expression is treated as case insensitive. If this character is not present, then the regular expression is case sensitive. The `regexp:match` function returns a node set of `match` elements, each of whose string value is equal to a portion of the first argument string that was captured by the regular expression. If the match is not global, the first match element has a value equal to the portion of the string matched by the entire regular expression. The following example illustrates a non-global match:
    <xsl:for-each select="regExp:match('http://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.xml',
                                       '(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)')">
       Part <xsl:value-of select="position()" /> = <xsl:value-of select="." />
    </xsl:for-each>
Gives the following result:
    Part 1 = http://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.xml
    Part 2 = http
    Part 3 = www.bayes.co.uk
    Part 4 =
    Part 5 = /xml/index.xml?/xml/utils/rechecker.xml
The following example illustrates a global match:
    <xsl:for-each select="regExp:match('This is a test string', '(\w+)', 'g'">
       Part <xsl:value-of select="position()" /> = <xsl:value-of select="." />
    </xsl:for-each>
Gives the following result:
    Part 1 = This
    Part 2 = is
    Part 3 = a
    Part 4 = test
    Part 5 = string
The following example illustrates another global match:
    <xsl:for-each select="regExp:match('This is a test string', '([a-z])+ ', 'g')">
       Part <xsl:value-of select="position()" /> = <xsl:value-of select="." />
    </xsl:for-each>
Gives the following result:
    Part 1 = his
    Part 2 = is
    Part 3 = a
    Part 4 = test
The following example illustrates a global, case-insensitive match:
    <xsl:for-each select="regExp:match('This is a test string', '([a-z])+ ', 'gi')">
       Part <xsl:value-of select="position()" /> = <xsl:value-of select="." />
    </xsl:for-each>
Gives the following result:
    Part 1 = This
    Part 2 = is
    Part 3 = a
    Part 4 = test
An implementation of this extension function in the EXSLT regexp namespace must conform to the behaviour described in this document. ## Implementations Built-in support for `regexp:match` is available in the following XSLT processors:
Processor | Processor Version | Implemented Version
--- | --- | ---
4XSLT, from 4Suite. | 0.12.0a3 | 1
The following implementations of `regexp:match` are available:
Language | Implemented Version | Creator | Date | Download
--- | --- | --- | --- | ---
Javascript | 1 | Chris Bayes | 2001-06-24 | regexp.match.js
Msxsl | 1 | Chris Bayes | 2001-06-24 | regexp.match.msxsl.xsl
## Use Cases Use Case Package: regexp.match.use-cases.zip The following use cases illustrate the functionality of `regexp:match`.
Details | Calling Stylesheet | XML Data | Expected Result | Category | Template
--- | --- | --- | --- | --- | ---
1 | regexp.match.1.xsl | regexp.match.data.1.xml | regexp.match.result.1.xml | example | N
## Change History Submitted: 2001-06-24 Creator: Chris Bayes(http://www.bayes.co.uk) Returns the nodes that match a regular expression.
Version | Modified | By | Details
--- | --- | --- | ---
1.1 | 2002-08-20 | Craig Stewart | Added 4XSLT implementation to the list.
1.2 | 2002-11-12 | Craig Stewart | Updated 4XSLT version to 0.12.0a3.

http://www.exslt.org/regexp/functions/match/regexp.match.html last modified 2002-11-12