replace
replaces each occurrence of a substring
(string subject, string search, string replace, boolean isRegex) -> string
Returns a string where each occurrence of search
in subject
is replaced with replace
. Replacement happens from left to right.
If isRegex
is true, interprets search
as a regular expression pattern. Capturing groups in the regular expression pattern are available as $1, $2, etc. in the replacement string.
See also:
Parameters
Name | Type | Description |
---|---|---|
subject |
string | The string to replace in |
search |
string | The substring to replace |
replace |
string | The replacement to use |
isRegex |
boolean |
If If |
Examples
-
Basic replacement
Arguments - subject
- hello world
- search
- hello
- replace
- greetings
- isRegex
- false
Result greetings world -
Referencing capturing groups
Arguments - subject
- alpha-42
- search
- (.*)-(.*)
- replace
- $2/$1
- isRegex
- true
Result 42/alpha