Hyperlinkv0.8.0-beta.28

String

String.replaceconsteffect/String.ts:263
(searchValue: string | RegExp, replaceValue: string): (
  self: string
) => string

Replaces matches in a string using String.prototype.replace.

Details

String search values and non-global regular expressions replace the first match; global regular expressions replace every match.

Example (Replacing a substring)

import { pipe, String } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(pipe("abc", String.replace("b", "d")), "adc")
assert.deepStrictEqual(
  pipe("hello world", String.replace("world", "Effect")),
  "hello Effect"
)
transforming
Source effect/String.ts:2632 lines
export const replace = (searchValue: string | RegExp, replaceValue: string) => (self: string): string =>
  self.replace(searchValue, replaceValue)