XQuery adds the concept of anchors to XML Schema regular expressions. In XML Schema validation, the regular expression is expected to match the entire string, not a part of it. For example, the regular expression str
matches only the string str
and not other strings that contain str
, like 5str5
. In XQuery, however, the expression str
matches all strings that contain
str
, including 5str5
.
Because of this looser interpretation, it is sometimes useful to explicitly say that the expression should match the beginning or end of the string (or both). Anchors can be used for this purpose. The ^
character is used to match the beginning of the string, and the $
character is used to match the end of the string. For example, the regular expression ^str
specifies that a matching string must start with str
. Table 18-13 shows some examples that use anchors.
Table 18-13. Anchors
Regular expression |
Strings that match |
Strings that do not match |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Some XQuery functions (namely matches
, replace
, and tokenize
) allow you to indicate that the processor should operate in multi-line mode. This is specified using the letter m
in the $flags
argument. In multi-line mode, anchors match not just the beginning and end of the entire string, but also the beginning and end of any line within the string, as indicated by a line feed character (#xA
). Table 18-14 shows some examples of using anchors in multi-line mode.
Table 18-14. Anchors in multi-line mode[a]
Regular expression |
Strings that match |
Strings that do not match |
---|---|---|
|
|
|
|
|
|
|
| |
| ||
| ||
|
|
|
|
| |
| ||
|
|
|
|
| |
| ||
[a] Some of the examples span several lines; individual examples are separated by commas. |
18.226.187.233