Anchors
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 |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Anchors and Multi-Line Mode
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access