The replace
function is used to search and replace a string with another string.
Parameters
value
(string): the string where you want to replace part of. This parameter is mandatory.search
(string): The string or regular expression to search for. This parameter is mandatory.isRegex
(boolean): A flag indicating whethersearch
is a regular expression. This parameter is mandatory.replace
(string): The string to replacesearch
with. This parameter is mandatory.
Examples
Here are a few examples of how to use the replace
function:
Example 1: Replace a string with another string
replace("I like apple", search="apple", isRegex=False, replace="orange")
This will replace all occurrences of the string "apple" with the string "orange".
Example 2: Replace a regular expression with a string
replace("A LIKE a", search="[a-z]", isRegex=True, replace="x")
This will replace all lowercase letters with the string "x".