Skip to content

Commit a682ed8

Browse files
authored
ESQL: Add example of regex REPLACE (#134664)
1 parent 207787a commit a682ed8

File tree

6 files changed

+48
-23
lines changed

6 files changed

+48
-23
lines changed

docs/reference/query-languages/esql/_snippets/functions/examples/replace.md

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/replace.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/docs/functions/replace.md

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/qa/testFixtures/src/main/resources/docs.csv-spec

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,20 +335,6 @@ date_string:keyword | date:date
335335
// end::dateParse-result[]
336336
;
337337

338-
docsReplace
339-
//tag::replaceString[]
340-
ROW str = "Hello World"
341-
| EVAL str = REPLACE(str, "World", "Universe")
342-
| KEEP str
343-
// end::replaceString[]
344-
;
345-
346-
//tag::replaceString-result[]
347-
str:keyword
348-
Hello Universe
349-
// end::replaceString-result[]
350-
;
351-
352338
docsCase
353339
// tag::case[]
354340
FROM employees

x-pack/plugin/esql/qa/testFixtures/src/main/resources/string.csv-spec

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,33 @@ first_name:keyword | result:keyword
12231223
Alejandro | null
12241224
;
12251225

1226+
docsReplaceText
1227+
//tag::replaceString[]
1228+
ROW str = "Hello World"
1229+
| EVAL str = REPLACE(str, "World", "Universe")
1230+
// end::replaceString[]
1231+
;
1232+
1233+
//tag::replaceString-result[]
1234+
str:keyword
1235+
Hello Universe
1236+
// end::replaceString-result[]
1237+
;
1238+
1239+
docsReplaceRegex
1240+
//tag::replaceRegex[]
1241+
ROW str = "Hello World"
1242+
| EVAL str = REPLACE(str, "\\s+", "")
1243+
// end::replaceRegex[]
1244+
;
1245+
1246+
//tag::replaceRegex-result[]
1247+
str:keyword
1248+
HelloWorld
1249+
// end::replaceRegex-result[]
1250+
;
1251+
1252+
12261253
left
12271254
// tag::left[]
12281255
FROM employees

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/Replace.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ public class Replace extends EsqlScalarFunction {
5050
description = """
5151
The function substitutes in the string `str` any match of the regular expression `regex`
5252
with the replacement string `newStr`.""",
53-
examples = @Example(
54-
file = "docs",
55-
tag = "replaceString",
56-
description = "This example replaces any occurrence of the word \"World\" with the word \"Universe\":"
57-
)
53+
examples = {
54+
@Example(
55+
file = "string",
56+
tag = "replaceString",
57+
description = "This example replaces any occurrence of the word \"World\" with the word \"Universe\":"
58+
),
59+
@Example(file = "string", tag = "replaceRegex", description = "This example removes all spaces:") }
5860
)
5961
public Replace(
6062
Source source,

0 commit comments

Comments
 (0)