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 |
The subject of the function. A modified copy is returned. |
substr |
The substring for which all instances will be replaced. |
repl |
The string that will replace all instances of |
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. |
ValueError |
If either substr or repl is not UTF-8 encoded. |
Examples
# Replace substring instances; returns "Goodbye World" - returnStep: return: ${text.replace_all("Hello World", "Hello", "Goodbye")}