This function replaces a search text (searchText) in the specified text with other text (replaceText).
The search text can optionally be a regular expression (isRegEx = true).
Syntax description and parameter list MUST be listed before a more detailed text or examples!
Tooltip
Syntax: $replace(text,searchText,replaceText[,isRegEx=false])
Parameter
Description
textThe text in which something is to be replaced.
searchTextThe text or regular expression to be replaced.
replaceTextThe text to be inserted.
isRegEx
(optional)Specifies whether the searchText is a regular expression. The default value is false.
Returns the text with the replaced parts.
Example: $replace(Hello world!,world,handbook) – Returns 'Hello handbook!'
Syntax
$replace(text,searchText,replaceText[,isRegEx=false])
Parameter
Name | Description |
|---|---|
text | The text in which something is to be replaced. |
searchText | The text or regular expression to be replaced. |
replaceText | The text to be inserted. |
isRegEx (optional) | Specifies whether the searchText is a regular expression. The default value is false. |
Return value
The replaced text.
Example
Listing of at least one or more examples.
Syntax | Result | Remarks |
|---|---|---|
$replace(Hello World!,World, Handbook) | Hello Handbook! | |
$replace(1234512345,3,9) | 1294512945 | |
$replace(1234512345,/3/,9,$true) | 129451235 | Since the 'Global' flag is not set for this regular expression, only the first instance applies! |
$replace(1234512345,/3/g,9,$true) | 1294512945 | Since the 'Global' flag is set for this regular expression, all instances apply.! |
$replace(Hello World!,/(\w+) (\w+)!/,$2 $1!,$true) | World Hello! | A match group in the replaceText can be accessed using $n. |