The replace
function is used to search and replace a string with the value from a variable.
Parameters
value
(string): the string where you want to replace part of. This parameter is mandatory.replace
(string): The variable to replacesearch
with. 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.
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", "orange", search="apple", isRegex=False)
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", "x", search="[a-z]", isRegex=True)
This will replace all lowercase letters with the string "x".