Skip to content

replace

Module Export

text |> (
pattern: regex
replacement: text
count: number|nothing
) => text

Replaces matching substring in a text.

replace replaces a matching substring count number of times from an input text. If count is not set, all matching substrings will be replaced.

Examples

Replace whitespace with underscore

import { replace } from 'text'
from 'This is a sentence' replace(/\s/, '_')
// Returns:
'This_is_a_sentence'