Skip to content

Commit 03ec453

Browse files
Add the optional limit argument to replace() (#1245)
Co-authored-by: Jens Pryce-Åklundh <[email protected]>
1 parent 8f3676a commit 03ec453

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ RETURN count(p) AS count
201201

202202
| Queries no longer require xref:clauses/with.adoc[`WITH`] to transition between reading and writing operations.
203203

204+
a|
205+
label:functionality[]
206+
label:updated[]
207+
[source, cypher, role="noheader"]
208+
----
209+
RETURN replace("hello world", "l", "", 1)
210+
----
211+
212+
| The xref:functions/string.adoc#functions-replace[`replace()`] function now accepts an optional `limit` argument, defining the number of times the search string is replaced.
213+
204214
|===
205215

206216
=== New in Cypher 25

modules/ROOT/pages/functions/string.adoc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,13 @@ RETURN normalize('\uFE64', NFKC) = '\u003C' AS result
323323

324324
.Details
325325
|===
326-
| *Syntax* 3+| `replace(original, search, replace)`
326+
| *Syntax* 3+| `replace(original, search, replace [, limit])`
327327
| *Description* 3+| Returns a `STRING` in which all occurrences of a specified search `STRING` in the given `STRING` have been replaced by another (specified) replacement `STRING`.
328-
.4+| *Arguments* | *Name* | *Type* | *Description*
328+
.5+| *Arguments* | *Name* | *Type* | *Description*
329329
| `original` | `STRING` | The string to be modified.
330330
| `search` | `STRING` | The value to replace in the original string.
331331
| `replace` | `STRING` | The value to be inserted in the original string.
332+
| `limit` | `STRING` | The maximum amount of times the search value should be replaced in the string, starting from the left. label:new[Introduced in Neo4j 2025.06]
332333
| *Returns* 3+| `STRING`
333334
|===
334335

@@ -337,6 +338,7 @@ RETURN normalize('\uFE64', NFKC) = '\u003C' AS result
337338

338339
| If any argument is `null`, `null` will be returned.
339340
| If `search` is not found in `original`, `original` will be returned.
341+
| If `limit` is not defined, all occurrences of the search will be replaced.
340342

341343
|===
342344

@@ -362,6 +364,24 @@ RETURN replace("hello", "l", "w")
362364
363365
|===
364366
367+
.Query with limit
368+
// tag::functions_string_replace[]
369+
[source, cypher, indent=0]
370+
----
371+
RETURN replace("hello", "l", "w", 1)
372+
----
373+
// end::functions_string_replace[]
374+
375+
.Result
376+
[role="queryresult",options="header,footer",cols="1*<m"]
377+
|===
378+
379+
| replace("hello", "l", "w", 1)
380+
| "hewlo"
381+
1+d|Rows: 1
382+
383+
|===
384+
365385
======
366386

367387

0 commit comments

Comments
 (0)