ES|QL REPLACE function
Replaces regular expression matches in a string with a replacement string.
string- String expression.
regex- Regular expression.
newString-
Replacement string.
The function substitutes in the string str any match of the regular expression regex with the replacement string newStr.
Note
If regex matches and the result is longer than 1MB, REPLACE returns null and emits a warning.
| string | regex | newString | result |
|---|---|---|---|
| keyword | keyword | keyword | keyword |
| keyword | keyword | text | keyword |
| keyword | text | keyword | keyword |
| keyword | text | text | keyword |
| text | keyword | keyword | keyword |
| text | keyword | text | keyword |
| text | text | keyword | keyword |
| text | text | text | keyword |
This example replaces any occurrence of the word "World" with the word "Universe":
ROW str = "Hello World"
| EVAL str = REPLACE(str, "World", "Universe")
| str:keyword |
|---|
| Hello Universe |
This example removes all spaces:
ROW str = "Hello World"
| EVAL str = REPLACE(str, "\\\\s+", "")
| str:keyword |
|---|
| HelloWorld |