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 TypeName | Type | Description |
$arg |
xs:string? |
the string to test |
$pattern |
xs:string |
the regular expression |
return value |
xs:integer |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:number-of-matches
( $arg as xs:string? ,
$pattern as xs:string ) as xs:integer {
count(tokenize($arg,$pattern)) - 1
} ; |
ExamplesXQuery Example | Results |
---|
functx:number-of-matches('abcabc','ab') |
2 |
functx:number-of-matches('12345','\d') |
5 |
functx:number-of-matches('aaaaaa','aaa') |
2 |
See Alsofn:matches | Whether a string matches a regular expression |
History |
Recommended Reading:
|