> ## Documentation Index
> Fetch the complete documentation index at: https://errand.nuvrel.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# replace

> Replace all occurrences of a substring.

`replace(str, substr, replace)` returns a copy of `str` with every occurrence of `substr` replaced by `replace`.

## Signature

```
replace(str string, substr string, replace string) string
```

## Example

Convert a Go module path to a filesystem-safe artifact name by replacing slashes with hyphens:

```hcl theme={null}
variable "module" {
  description = "Go module path"
  type        = string
  default     = "github.com/myorg/myapp"
}

variable "version" {
  type = string
}

computed "artifact_name" {
  description = "Artifact filename safe for use on the filesystem"
  expression  = "${replace(var.module, "/", "-")}-${var.version}.tar.gz"
}

task "package" {
  description = "Build and archive the release binary"
  commands = [
    "go build -o bin/app ./cmd/app",
    "tar -czf ${computed.artifact_name} bin/app",
  ]
}
```

`github.com/myorg/myapp` becomes `github.com-myorg-myapp-1.0.0.tar.gz`.

## Notes

* `replace` replaces all occurrences. There is no option to replace only the first match.
* For pattern-based replacement, use [`regexreplace`](/functions/string/regexreplace).
