EXSLT - regexp:replace

Implementer Page: regexp.replace.html
Function Package: regexp.replace.zip

Function Syntax

string regexp:replace(string, string, string, string)

The regexp:replace function replaces the parts of a string that match a regular expression with another string.

The first argument is the string to be matched and replaced. The second argument is a regular expression that follows the Javascript regular expression syntax. The fourth argument is the string to replace the matched parts of the string.

The third argument is a string consisting of character flags to be used by the match. If a character is present then that flag is true. The flags are:

  • g: global replace - all occurrences of the regular expression in the string are replaced. If this character is not present, then only the first occurrence of the regular expression is replaced.
  • i: case insensitive - the regular expression is treated as case insensitive. If this character is not present, then the regular expression is case sensitive.


The following XSLT processors support regexp:replace:

Implementations of regexp:replace are available in the following languages:



The following example shows how to use the regexp:replace function:


   <c>Is this EXSLT? No. no</c>


<xsl:template match="a">
   <xsl:apply-templates />
<xsl:template match="*">
      <xsl:value-of select="." />
               <xsl:value-of select="regexp:replace(string(.), 'no', 'g', 'yes!!!')" />
      <xsl:value-of select="regexp:replace(string(.), 'no', 'gi', 'yes!!!')" />
      <xsl:apply-templates select="*" />


<out>Is this EXSLT? No. no -
         Is this EXSLT? No. yes!!!Is this EXSLT? yes!!!. yes!!!</out>

http://www.exslt.org/regexp/functions/replace/index.html last modified 2002-11-12