fn:matches
Returns true if the given string matches the given regular expression.
matches($value as xs:string?, $pattern as xs:string, $flags as xs:string?:="") ➔ xs:boolean
Arguments | ||||
| $value | xs:string? | The string to be matched against a regular expression | |
| $pattern | xs:string | The regular expression | |
| $flags | xs:string? | := "" | Flags that control the interpretation of the regular expression |
Result | xs:boolean | |||
Namespace
http://www.w3.org/2005/xpath-functions
Links to W3C specifications
XPath 3.1 Functions and Operators
XPath 4.0 Functions and Operators
Saxon availability
Available in XPath 2.0, XSLT 2.0, XQuery 1.0, and later versions. Available in all Saxon editions. Available for all platforms.
Notes on the Saxon implementation
Saxon 9.3 introduced support for the q flag, and for XPath 3.0 regular
expression enhancements, provided XPath 3.0 is enabled.
Saxon implements some extensions to the flags argument. The value of this argument
contains the standard flags defined in the spec (i, m,
s, x, q) followed optionally by a semicolon and
then Saxon-specific flags. The Saxon-specific flags are:
-
j- Use the standard Java regular expression engine, allowing native Java regex syntax. This allows, for example, the use of "\b" in a regular expression to match word boundaries.If used with SaxonCS, the
jflag is treated as ifnwere specified. -
n- Use the standard .NET regular expression engine, allowing native .NET regex syntax. This is supported in SaxonCS only. -
g- Switch on diagnostics. Not currently used. -
k- Treat unknown Unicode block names as matching any character (this is the default for XSD 1.1). This option applies to the Saxon regular expression engine only. -
K- Treat unknown Unicode block names as an error (this is the default for XSD 1.0 and for XPath/XSLT/XQuery). This option applies to the Saxon regular expression engine only.
If the native regex engine is used, then the flags preceding the semicolon are interpreted as follows:
-
For Java:
-
'd': Pattern.UNIX_LINES -
'm': Pattern.MULTILINE -
'i': Pattern.CASE_INSENSITIVE -
's': Pattern.DOTALL -
'x': Pattern.COMMENTS -
'u': Pattern.UNICODE_CASE -
'q': Pattern.LITERAL -
'c': Pattern.CANON_EQ
-
-
For .NET:
-
'd': RegexOptions.Multiline -
'm': RegexOptions.Multiline -
'i': RegexOptions.IgnoreCase -
's': RegexOptions.Singleline -
'x': RegexOptions.IgnorePatternWhitespace -
'u': ignored -
'q': ignored -
'c': ignored
-
In the case of fn:replace(), if the
platform-native regex engine is used (Java or .NET) then the syntax for the replacement
expression in the third argument also follows the rules for the platform. For example, the
syntax ${name} can be used in a reference to a named captured group.