Description
The fn:matches function determines whether a string matches a regular expression. The regular expression syntax used is defined by XML Schema with a few modifications/additions in XQueryXPath/XSLT 2.0. The $pattern argument is a regular expression. Unlike many of the string-related functions, the fn:matches function does not use collations at all. Regular expression matching is solely based on Unicode code points. Unless the anchors "^" or "$" are used, the function returns true if any substring of $input matches the regular expression.
The $flags parameter allows for additional options in the interpretation of the regular expression. Flags and regular expressions are covered in detail in chapter 18 of the book XQuery.
For more examples of XQueryXPath/XSLT 2.0/XML Schema regular expressions, see this page.
This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book. Arguments and Return TypeName | Type | Description |
$input |
xs:string? |
the string to test |
$pattern |
xs:string |
the regular expression to test for |
$flags |
xs:string |
flags that control multiline mode, case insensitivity, etc. |
return value |
xs:boolean |
Examples<xsl:variable name="address" as="item()*"> | | '123123 Main Street
Traverse City, MI 49684' |
| </xsl:variable> |
XPath Example | Results |
---|
matches('query', 'q') |
true |
matches('query', 'ue') |
true |
matches('query', '^qu') |
true |
matches('query', 'qu$') |
false |
matches('query', '[ux]') |
true |
matches('query', 'q.*') |
true |
matches('query', '[a-z]{5}') |
true |
matches((), 'q' ) |
false |
matches('query', '[qu') |
Error FORX0002 |
matches($address, 'Street.*City') |
false |
matches($address, 'Street.*City', 's') |
true |
matches($address, 'Street$') |
false |
matches($address, 'Street$', 'm') |
true |
matches($address, 'street') |
false |
matches($address, 'street', 'i') |
true |
matches($address, 'Main Street') |
true |
matches($address, 'Main Street', 'x') |
false |
matches($address, 'Main \s Street', 'x') |
true |
matches($address, 'street$', 'im') |
true |
matches($address, 'Street$', 'q') |
Error FORX0001 |
See AlsoHistory |
Recommended Reading:
|