fn:replace

Replaces bits of a string using patternmatching.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

fn:replace(string $input, string $pattern, string $replacement) => string
fn:matches(string $input, string $pattern, string $replacement, string $flags) => string

Description

The function returns the input string wherein all occurrences of $pattern are replaced by $replacement influenced by the value of $flags, if present.

Argument

$input

a string to be modified

$pattern

a pattern

$replacement

a string to be inserted

$flags

modifiers for patternmatching

Example

  • For each string replace "x" with "y".

    for $value in ("axa","bxb","cxc")
    return replace($value,"x","y")

    The query returns:

    <xq:result>
      <xq:value>aya</xq:value>
      <xq:value>byb</xq:value>
      <xq:value>cyc</xq:value>
    </xq:result>