home contribute faq download

FunctX XQuery Functions

functx:number-of-matches

The number of regions that match a pattern

Google
Webxqueryfunctions.com

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

NameTypeDescription
$arg xs:string? the string to test
$pattern xs:string the regular expression
return value xs:integer

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for July 2004 - January 2007 (1.0):
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
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function number-of-matches 
  ( $arg as xs:string? ,
    $pattern as xs:string )  as xs:integer {
       
   fn:count(fn:tokenize($arg,$pattern)) - 1
 }

Examples

XQuery ExampleResults
functx:number-of-matches('abcabc','ab')
2
functx:number-of-matches('12345','\d')
5
functx:number-of-matches('aaaaaa','aaa')
2

See Also

fn:matchesWhether a string matches a regular expression

History

Published OnLast UpdatedContributor(s)
2006-07-092007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley