2019-10-21 04:22:28 -04:00
|
|
|
---
|
|
|
|
title: replace
|
|
|
|
description: Replaces all occurrences of the search string with the replacement string.
|
|
|
|
date: 2017-02-01
|
|
|
|
publishdate: 2017-02-01
|
2020-10-06 10:22:20 -04:00
|
|
|
lastmod: 2020-09-07
|
2019-10-21 04:22:28 -04:00
|
|
|
categories: [functions]
|
|
|
|
menu:
|
|
|
|
docs:
|
|
|
|
parent: "functions"
|
2022-12-02 03:19:23 -05:00
|
|
|
keywords: [replace]
|
|
|
|
signature:
|
|
|
|
- "replace INPUT OLD NEW [LIMIT]"
|
|
|
|
- "strings.Replace INPUT OLD NEW [LIMIT]"
|
2019-10-21 04:22:28 -04:00
|
|
|
workson: []
|
|
|
|
hugoversion:
|
2022-12-02 03:19:23 -05:00
|
|
|
relatedfuncs: [replaceRE]
|
2019-10-21 04:22:28 -04:00
|
|
|
deprecated: false
|
|
|
|
aliases: []
|
|
|
|
---
|
|
|
|
|
2020-10-06 10:22:20 -04:00
|
|
|
Replace returns a copy of `INPUT` with all occurrences of `OLD` replaced with `NEW`.
|
|
|
|
The number of replacements can be limited with an optional `LIMIT` parameter.
|
|
|
|
|
2019-10-21 04:22:28 -04:00
|
|
|
```
|
|
|
|
`{{ replace "Batman and Robin" "Robin" "Catwoman" }}`
|
|
|
|
→ "Batman and Catwoman"
|
2020-10-06 10:22:20 -04:00
|
|
|
|
|
|
|
{{ replace "aabbaabb" "a" "z" 2 }} → "zzbbaabb"
|
2019-10-21 04:22:28 -04:00
|
|
|
```
|