fn:replace
The fn:replace
function replaces parts of a string that match a regular expression. The regular expression syntax used is defined by XML Schema with a few modifications/additions in XQueryXPath/XSLT. The $pattern
argument is a regular expression. While it is nice to have the power of regular expressions, if you simply want to replace a particular sequence of characters you don't have to be familiar with regular expressions to do that; you can just specify the string you want replaced for $pattern
, as long as it doesn't contain any special characters.
The $replacement
argument specifies a string (not a pattern) that is to be used as a replacement.
The $flags
argument allows for additional options in the interpretation of the regular expression, such as multi-line processing and case insensitivity. Flags, reluctant quantifiers and sub-expressions are features that are covered.
For more examples of XQueryXPath/XSLT/XML Schema regular expressions,
This description is © Copyright 2007, O'Reilly Media. 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 Type
Name | Type | Description |
---|---|---|
$input | xs:string? | the string to change |
$pattern | xs:string | regular expression to match the areas to be replaced |
$replacement | xs:string | the replacement string |
$flags | xs:string | flags that control multiline mode, case insensitivity, etc. |
return value | xs:string |
Examples
XQuery Example | Results | |
---|---|---|
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
| Error FORX0003 | |
| Error FORX0002 | |
|
| |
The following examples show the difference between reluctant and regular quantifiers: | ||
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
The following examples exhibit the use of sub-expressions: | ||
|
| |
|
| |
|
| |
|
| |
|
|