Stay organized with collections
Save and categorize content based on your preferences.
Replaces all instances of a substring with a new string.
In the case of overlapping matches the leftmost instance is replaced.
If the expression is empty, it matches at the beginning of the string and
after each code point, yielding up to k+1 replacements for a string with
k code points.
Arguments
Arguments
source
string
The subject of the function. A modified copy is returned.
substr
string
The substring for which all instances will be replaced.
repl
string
The string that will replace all instances of substr.
Returns
A copy of source where all matches of substr are replaced by repl.
Raised exceptions
Exceptions
TypeError
If either source, substr, or repl is not a string.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Function: text.replace_all\n\nReplaces all instances of a substring with a new string.\n\nIn the case of overlapping matches the leftmost instance is replaced.\nIf the expression is empty, it matches at the beginning of the string and\nafter each code point, yielding up to `k+1` replacements for a string with\n`k` code points.\n\nArguments\n---------\n\nReturns\n-------\n\nA copy of `source` where all matches of `substr` are replaced by `repl`.\n\nRaised exceptions\n-----------------\n\nExamples\n--------\n\n```yaml\n# Replace substring instances; returns \"Goodbye World\"\n- returnStep:\n return: ${text.replace_all(\"Hello World\", \"Hello\", \"Goodbye\")}\n```"]]