O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

[2.0] replace()

Given an input string, a regular expression, and a replacement string, replaces all matches of the regular expression in the input string with the replacement string.

Syntax

xs:string replace($input as xs:string?, $pattern as xs:string, 
                  $replacement as xs:string)
xs:string replace($input as xs:string?, $pattern as xs:string, 
                  $replacement as xs:string, $flags as xs:string)

Inputs

Three strings; the first string is the original string, the second is a regular expression, and the third is a replacement string. There is also an optional fourth string that specifies flags for how the regular expression should be processed.

Note

It is a fatal error if a regular expression matches a zero-length string. See Appendix E for more details.

Outputs

An updated string in which all matches of the regular expression have been replaced with the replacement string.

Here are the details about how replace() actually works:

  • If the regular expression doesn’t match anything in the input string, the input string is returned unchanged.

  • If the regular expression matches two overlapping strings in the input string, only the first match is replaced.

  • Regular expression matching does not use collations; the characters’ Unicode code points are compared. Cases in which different characters are considered equal in the world’s languages are not taken into account.

  • The input string and the replacement string can both be zero-length strings. If the input string is a zero-length string, a zero-length string is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required