Hi, I'm Ask INFA!
What would you like to know?
ASK INFAPreview
Please to access Ask INFA.

Table of Contents

Search

  1. Preface
  2. Understanding Data Types and Field Properties
  3. Designing Processes
  4. Using and Displaying Data
  5. Designing Guides
  6. Designing Process Objects
  7. Designing Service Connectors
  8. Using App Connections
  9. System Services, Listeners and Connectors
  10. Designing Human Tasks

Design

Design

replace

replace

The replace function in XQuery is used to replace parts of a string that match a specified regular expression with a replacement string. This function is highly useful for string manipulation tasks such as text sanitation, formatting, and transformation.

Syntax

fn:replace(input, pattern, replacement, flags)
The following table describes the argument for this command:
Argument
Required/Optional
Description
input
Required
The input string to be processed. If this argument is an empty sequence (
()
), it is treated as an empty string.
pattern
Required
A regular expression pattern that specifies what part of the input string to replace. The pattern must be a valid regular expression.
replacement
Required
The string that will replace each substring of the input string that matches the regular expression pattern. Special replacement strings, such as
$1
, can be used to refer to captured groups within the pattern.
flags
A string of flags that modify the behavior of the regular expression as follows:
  • s
    : Single-line mode, where the dot (.) matches all characters, including newline.
  • m
    : Multi-line mode, where start
    ^
    and end
    $
    anchors match the start and end of any line.
  • i
    : Case-insensitive mode.

Return Value

  • Returns the
    xs:string
    that is obtained by replacing each non-overlapping substring of
    $input
    that matches the given
    $pattern
    with an occurrence of the
    $replacement
    string.
  • If no portions match, the original string is returned unchanged.

Examples

The following table lists some sample values and return values:
SAMPLE FUNCTION
OUTPUT
fn:replace('query', 'r', 'as')
queasy
fn:replace('query', 'qu', 'quack')
quackery
fn:replace('query', '[ry]', 'l')
quell
fn:replace('query', '[ry]+', 'l')
quel
fn:replace('query', 'z', 'a')
query
fn:replace('query', 'query', '')
zero-length string
fn:replace( (), 'r', 'as')
zero-length string
fn:replace('query', 'r?', 'as')
Error FORX0003
fn:replace('query', '(r', 'as')
Error FORX0002
fn:replace('Chapter', '(Chap)|(Chapter)', 'x')
xter
The following examples show the difference between reluctant and regular quantifiers:
SAMPLE FUNCTION
OUTPUT
fn:replace('reluctant', 'r.*t', 'X')
X
fn:replace('reluctant', 'r.*?t', 'X')
Xant
fn:replace('aaah', 'a{2,3}', 'X')
Xh
fn:replace('aaah', 'a{2,3}?', 'X')
Xah
fn:replace('aaaah', 'a{2,3}', 'X')
Xah
fn:replace('aaaah', 'a{2,3}?', 'X')
XXh
The following examples exhibit the use of sub-expressions:
SAMPLE FUNCTION
OUTPUT
fn:replace('Chap 2...Chap 3...Chap 4...', 'Chap (\d)', 'Sec $1.0')
Sec 2.0...Sec 3.0...Sec 4.0...
fn:replace('abc123', '([a-z])', '$1x')
axbxcx123
fn:replace('2315551212', '(\d{3})(\d{3})(\d{4})', '($1) $2-$3')
(231) 555-1212
fn:replace('2006-10-18', '\d{2}(\d{2})-(\d{2})-(\d{2})', '$2/$3/$1')
10/18/06
fn:replace('25', '(\d+)', '\$$1.00')
$25.00

0 COMMENTS

We’d like to hear from you!