matches function
The fn:matches function determines whether a string matches a specific pattern.
Syntax
- source-string
- A string that is compared to a pattern.
source-string is an xs:string value or the empty sequence.
- pattern
- A regular expression that is compared to source-string.
A regular expression is a set of characters, wildcards, and operators
that define a string or group of strings in a search pattern.
pattern is an xs:string value.
- flags
- An xs:string value that can contain any of the following values
that control matching of pattern to source-string:
- s
- Indicates that the dot (.) matches any character.
If the s flag is not specified, the dot (.) matches any character except the new line character (X'0A').
- m
- Indicates that the caret (^) matches the start of a line (the
position after a new line character), and the dollar sign ($) matches
the end of a line (the position before a new line character).
If the m flag is not specified, the caret (^) matches the start of the string, and the dollar sign ($) matches the end of the string.
- i
- Indicates that matching is case-insensitive.
If the i flag is not specified, case-sensitive matching is done.
- x
- Indicates that whitespace characters within pattern are
ignored.
If the x flag is not specified, whitespace characters are used for matching.
- Limitation of length
The length of source-string and pattern is limited to 32000 bytes.
Returned value
If source-string is not the empty sequence, the returned value is true if source-string matches pattern. The returned value is false if source-string does not match pattern.
If pattern does not contain the string- or line-starting character caret (^), or the string- or line-ending character dollar sign ($), source-string matches pattern if any substring of source-string matches pattern. If pattern contains the string- or line-starting character caret (^), source-string matches pattern only if source-string matches pattern from the beginning of source-string or the beginning of a line in source-string. If pattern contains the string- or line-ending character dollar sign ($), source-string matches pattern only if source-string matches pattern at the end of source-string or at the end of a line of source-string. The m flag determines whether the match occurs from the beginning of the string or the beginning of a line.
If source-string is the empty sequence, the returned value is false.
Examples
fn:matches("abbcacadbdcd","(ac)|(bd)")
The returned value is true.
fn:matches("bd","^(ac)|(bd)$")
The returned value is true.
fn:matches("abc1234","ABC 1234", "ix")
The returned value is true.