Replace all occurrences of a value in a String, Number, or Array with another value.
Syntax
Parameters
subject
- The entity to search.search
- The value(s) to search for.subject
is searched for any occurrences of the String.subject
is a String, it is searched for any occurrences of any of the items in needle
. Otherwise, if subject
is an Array, only sub-Arrays that match needle
will be found.subject
is an Array, in which case, any occurrences will be searched for.replace
- The value(s) to use for replacement.search
will be replaced with the String.subject
is a String, and search
is an Array, all matches will be replaced by the corresponding value in the replace
Array - or an empty value if there are no corresponding items. Otherwise, if subject
is an Array, replace
will be used to replace matching sub-Arrays.subject
is an Array, in which case, all matches of search
will be replaced.strict
- Whether to employ strict matching.false
(default) - If subject
is a String, the match will be case-insensitive. Otherwise, if subject
is an Array, item types will not be checked, only item values.true
- If subject
is a String, the match will be case-sensitive. Otherwise, if subject
is an Array, item types will have to match as well as values. Array searches are always case-sensitive.
Result
subject
.
Returns subject
with all occurrences of search
replaced with the corresponding replace
value.
To count how many matches there are before replacement, search()
can be used.