﻿---
title: ES|QL REPLACE function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/3001/reference/query-languages/esql/functions-operators/string-functions/replace
products:
  - Elasticsearch
---

# ES|QL REPLACE function
## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/3001/reference/query-languages/esql/images/functions/replace.svg)


## Parameters

<definitions>
  <definition term="string">
    String expression.
  </definition>
  <definition term="regex">
    Regular expression.
  </definition>
  <definition term="newString">
    Replacement string.
  </definition>
</definitions>


## Description

The function substitutes in the string `str` any match of the regular expression `regex` with the replacement string `newStr`.

## Supported types


| 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 |


## Examples

This example replaces any occurrence of the word "World" with the word "Universe":
```esql
ROW str = "Hello World"
| EVAL str = REPLACE(str, "World", "Universe")
```


| str:keyword    |
|----------------|
| Hello Universe |

This example removes all spaces:
```esql
ROW str = "Hello World"
| EVAL str = REPLACE(str, "\\\\s+", "")
```


| str:keyword |
|-------------|
| HelloWorld  |