viv:replace

replaces substrings that match a regex with another string

Synopsis

string
	viv:replace
	(str, pattern, newstr, replace-flags);
string    str;
string    pattern;
string    newstr;
""|"g"|"i"|"gi"    replace-flags;

Description

Replace the substrings in str matching the POSIX regex pattern pattern with newstr. Note that back references are NOT supported.

Arguments

  • str: string on which to do the replacement(s).
  • pattern: regex pattern (see the regex specification or RegularExpression.info for detailed information).
  • newstr: replacement string.
  • replace-flags:
    • g: replace all occurrences.
    • i: case-insensitive pattern.

    The default value for this parameter is the empty string, '""'.

Arguments

str in which the replacement has been performed.

Example

    <xsl:value-of select="viv:replace(
    document/@url,
    '(domain1|domain2)\.com',
    'domain3.com', 'gi')" />