Description
The functx:number-of-matches function counts the number of times a string matches a particular pattern (regular expression). It does not count overlapping regions.
Arguments and Return Type| Name | Type | Description |
$arg |
xs:string? |
the string to test |
$pattern |
xs:string |
the regular expression |
| return value |
xs:integer |
XSLT Function Declaration| See XQuery definition. | | XSLT 2.0 Syntax: |
|---|
<xsl:function name="functx:number-of-matches" as="xs:integer"
xmlns:functx="http://www.functx.com" >
<xsl:param name="arg" as="xs:string?"/>
<xsl:param name="pattern" as="xs:string"/>
<xsl:sequence select="
count(tokenize($arg,$pattern)) - 1
"/>
</xsl:function>
|
Examples| XSLT Example | Results |
|---|
functx:number-of-matches('abcabc','ab')
|
2
|
functx:number-of-matches('12345','\d')
|
5
|
functx:number-of-matches('aaaaaa','aaa')
|
2
|
See Also| fn:matches | Whether a string matches a regular expression |
History |
|