@loradb/lora-node 0.36.0 → 0.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/docs/README.md +86 -0
- package/docs/concepts/graph-model.md +270 -0
- package/docs/concepts/nodes.md +285 -0
- package/docs/concepts/properties.md +348 -0
- package/docs/concepts/relationships.md +325 -0
- package/docs/concepts/result-formats.md +183 -0
- package/docs/concepts/schema-free.md +183 -0
- package/docs/cookbook.md +1081 -0
- package/docs/data-types/lists-and-maps.md +406 -0
- package/docs/data-types/overview.md +210 -0
- package/docs/data-types/scalars.md +376 -0
- package/docs/data-types/spatial.md +291 -0
- package/docs/data-types/temporal.md +355 -0
- package/docs/data-types/vectors.md +563 -0
- package/docs/errors.md +183 -0
- package/docs/functions/aggregation.md +372 -0
- package/docs/functions/list.md +522 -0
- package/docs/functions/map.md +207 -0
- package/docs/functions/math.md +421 -0
- package/docs/functions/number.md +197 -0
- package/docs/functions/overview.md +545 -0
- package/docs/functions/spatial.md +384 -0
- package/docs/functions/string.md +502 -0
- package/docs/functions/temporal.md +590 -0
- package/docs/functions/utility.md +137 -0
- package/docs/functions/vectors.md +772 -0
- package/docs/getting-started/installation.md +204 -0
- package/docs/getting-started/node.md +582 -0
- package/docs/getting-started/tutorial.md +334 -0
- package/docs/index.md +203 -0
- package/docs/limitations.md +291 -0
- package/docs/performance.md +219 -0
- package/docs/queries/aggregation.md +520 -0
- package/docs/queries/cheat-sheet.md +302 -0
- package/docs/queries/constraints.md +239 -0
- package/docs/queries/create.md +331 -0
- package/docs/queries/examples.md +453 -0
- package/docs/queries/index.md +169 -0
- package/docs/queries/indexes.md +546 -0
- package/docs/queries/match.md +429 -0
- package/docs/queries/ordering.md +359 -0
- package/docs/queries/parameters.md +328 -0
- package/docs/queries/paths.md +462 -0
- package/docs/queries/return-with.md +500 -0
- package/docs/queries/set-delete.md +369 -0
- package/docs/queries/unwind-merge.md +358 -0
- package/docs/queries/where.md +416 -0
- package/docs/snapshot.md +545 -0
- package/docs/troubleshooting.md +1158 -0
- package/docs/wal.md +570 -0
- package/docs/why.md +273 -0
- package/package.json +13 -14
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "String Functions"
|
|
3
|
+
description: "String functions in LoraDB — string.slice, string.replace, string.split, string.join, string.normalize, string.slugify, regex helpers, case conversion, and numeric parsing."
|
|
4
|
+
online: "https://loradb.com/docs/functions/string"
|
|
5
|
+
package: "@loradb/lora-node@0.36.2"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# String Functions
|
|
9
|
+
|
|
10
|
+
Every function on this page returns `null` when any argument is
|
|
11
|
+
`null`, unless the function explicitly documents a different fallback.
|
|
12
|
+
String slicing and length helpers count Unicode code points, not UTF-8
|
|
13
|
+
bytes. Regex helpers and `string.find` report Rust regex/string byte
|
|
14
|
+
offsets.
|
|
15
|
+
|
|
16
|
+
## Overview
|
|
17
|
+
|
|
18
|
+
| Goal | Function |
|
|
19
|
+
|---|---|
|
|
20
|
+
| Case conversion | [`string.lower`, `string.upper`](#tolower--toupper) |
|
|
21
|
+
| Case style conversion | [`string.capitalize`, `string.case`, `string.swap_case`](#case-style) |
|
|
22
|
+
| Trim whitespace | [`string.trim`, `string.trim_left`, `string.trim_right`](#trim--ltrim--rtrim) |
|
|
23
|
+
| Substring replace | [`string.replace`](#replace) |
|
|
24
|
+
| Count / find text | [`string.find`, `string.count`, `string.before`, `string.after`](#find-count-before-after) |
|
|
25
|
+
| Substring slice | [`string.slice`](#substring) |
|
|
26
|
+
| Left / right slice | [`string.prefix`, `string.suffix`](#left--right) |
|
|
27
|
+
| Split / join | [`string.split`, `string.join`, `string.words`](#split) |
|
|
28
|
+
| Blank check | [`string.is_blank`](#stringis_blank) |
|
|
29
|
+
| Reverse | [`string.reverse`](#reverse) |
|
|
30
|
+
| Length | [`string.length`, `value.size`](#stringlength--valuesize) |
|
|
31
|
+
| Pad | [`string.pad_left`, `string.pad_right`](#lpad--rpad) |
|
|
32
|
+
| Slug / escape / URL | [`string.slugify`, `string.escape`, `string.url_encode`, `string.url_decode`](#encoding-and-escaping) |
|
|
33
|
+
| Normalise Unicode | [`string.normalize`](#normalize) |
|
|
34
|
+
| Convert type | [`toString`, `toInteger`, `toFloat`, `toBoolean`](#type-conversion) |
|
|
35
|
+
| Prefix bound | [`string.prefix_end`](#stringprefix_end) |
|
|
36
|
+
| Predicate in `WHERE` | [`STARTS WITH`, `ENDS WITH`, `CONTAINS`, `=~`](#string-operators-in-where) |
|
|
37
|
+
|
|
38
|
+
## string.lower / string.upper {#tolower--toupper}
|
|
39
|
+
|
|
40
|
+
Unicode case conversion.
|
|
41
|
+
|
|
42
|
+
```cypher
|
|
43
|
+
RETURN string.lower('Ada LoveLace'); // 'ada lovelace'
|
|
44
|
+
RETURN string.upper('ada') // 'ADA'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Non-ASCII letters follow Rust's Unicode case mapping:
|
|
48
|
+
|
|
49
|
+
```cypher
|
|
50
|
+
RETURN string.lower('Ångström') // 'ångström'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Case Style
|
|
54
|
+
|
|
55
|
+
Use `string.capitalize(s)` for the first character, or
|
|
56
|
+
`string.capitalize(s, true)` to capitalize each whitespace-delimited word.
|
|
57
|
+
Use `string.case(s, style)` when generating identifiers or display text.
|
|
58
|
+
|
|
59
|
+
```cypher
|
|
60
|
+
RETURN string.capitalize('ada lovelace'); // 'Ada lovelace'
|
|
61
|
+
RETURN string.capitalize('ada lovelace', true); // 'Ada Lovelace'
|
|
62
|
+
RETURN string.case('hello world', 'camel'); // 'helloWorld'
|
|
63
|
+
RETURN string.case('helloWorld', 'snake'); // 'hello_world'
|
|
64
|
+
RETURN string.swap_case('LoraDB') // 'lORAdb'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Supported `string.case` styles are `'camel'`, `'pascal'`, `'snake'`,
|
|
68
|
+
`'kebab'`, `'screaming_snake'` / `'constant'`, and `'title'`.
|
|
69
|
+
|
|
70
|
+
### Case-insensitive matching
|
|
71
|
+
|
|
72
|
+
```cypher
|
|
73
|
+
MATCH (u:User)
|
|
74
|
+
WHERE string.lower(u.email) = string.lower($search)
|
|
75
|
+
RETURN u
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```cypher
|
|
79
|
+
MATCH (u:User)
|
|
80
|
+
WHERE string.lower(u.name) STARTS WITH string.lower($prefix)
|
|
81
|
+
RETURN u
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## string.trim / string.trim_left / string.trim_right {#trim--ltrim--rtrim}
|
|
85
|
+
|
|
86
|
+
Strip whitespace from both ends / left / right.
|
|
87
|
+
|
|
88
|
+
```cypher
|
|
89
|
+
RETURN string.trim(' hi '); // 'hi'
|
|
90
|
+
RETURN string.trim_left(' hi '); // 'hi '
|
|
91
|
+
RETURN string.trim_right(' hi ') // ' hi'
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Common for cleaning up user input before storage:
|
|
95
|
+
|
|
96
|
+
```cypher
|
|
97
|
+
UNWIND $rows AS row
|
|
98
|
+
CREATE (:Contact {email: string.lower(string.trim(row.email))})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## string.replace {#replace}
|
|
102
|
+
|
|
103
|
+
`string.replace(str, find, replacement)` — replaces every occurrence.
|
|
104
|
+
|
|
105
|
+
```cypher
|
|
106
|
+
RETURN string.replace('banana', 'a', 'o'); // 'bonono'
|
|
107
|
+
RETURN string.replace('hello', 'x', 'y'); // 'hello'
|
|
108
|
+
RETURN string.replace('abc def', ' ', '_') // 'abc_def'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Multi-step replace
|
|
112
|
+
|
|
113
|
+
```cypher
|
|
114
|
+
WITH 'Joe O\'Brien' AS raw
|
|
115
|
+
RETURN string.replace(string.replace(raw, ' ', '_'), '\'', '') AS slug
|
|
116
|
+
// 'Joe_OBrien'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## string.find / string.count / string.before / string.after {#find-count-before-after}
|
|
120
|
+
|
|
121
|
+
Use these helpers when you need positions or delimiter-based extraction
|
|
122
|
+
inside one row.
|
|
123
|
+
|
|
124
|
+
| Function | Behaviour |
|
|
125
|
+
|---|---|
|
|
126
|
+
| `string.find(s, needle)` | First byte offset, or `-1` when missing |
|
|
127
|
+
| `string.find(s, needle, true)` | All byte offsets as a list |
|
|
128
|
+
| `string.count(s, needle)` | Non-overlapping occurrence count |
|
|
129
|
+
| `string.before(s, needle)` | Text before the first occurrence, or `null` |
|
|
130
|
+
| `string.after(s, needle)` | Text after the first occurrence, or `null` |
|
|
131
|
+
|
|
132
|
+
```cypher
|
|
133
|
+
RETURN string.find('banana', 'na'); // 2
|
|
134
|
+
RETURN string.count('banana', 'na'); // 2
|
|
135
|
+
RETURN string.before('a=b=c', '='); // 'a'
|
|
136
|
+
RETURN string.after('a=b=c', '='); // 'b=c'
|
|
137
|
+
RETURN string.after('abc', '=') // null
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Regex patterns can be used with `string.count` by wrapping the pattern
|
|
141
|
+
in slashes:
|
|
142
|
+
|
|
143
|
+
```cypher
|
|
144
|
+
RETURN string.count('a1 b22 c333', '/\d+/') // 3
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
An empty `needle` returns `null`; pass a concrete delimiter or regex so
|
|
148
|
+
the count has a clear meaning.
|
|
149
|
+
|
|
150
|
+
## string.slice {#substring}
|
|
151
|
+
|
|
152
|
+
`string.slice(str, start[, length])` — 0-based indices.
|
|
153
|
+
|
|
154
|
+
```cypher
|
|
155
|
+
RETURN string.slice('loradb', 0, 4); // 'lora'
|
|
156
|
+
RETURN string.slice('loradb', 4); // 'db'
|
|
157
|
+
RETURN string.slice('hello', 1, 3) // 'ell'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Out-of-range indices return an empty string rather than an error.
|
|
161
|
+
|
|
162
|
+
```cypher
|
|
163
|
+
RETURN string.slice('hi', 99); // ''
|
|
164
|
+
RETURN string.slice('hi', 0, 99) // 'hi'
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## string.prefix / string.suffix {#left--right}
|
|
168
|
+
|
|
169
|
+
```cypher
|
|
170
|
+
RETURN string.prefix('graphdb', 5); // 'graph'
|
|
171
|
+
RETURN string.suffix('graphdb', 2) // 'db'
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Length exceeding the input returns the whole string:
|
|
175
|
+
|
|
176
|
+
```cypher
|
|
177
|
+
RETURN string.prefix('ab', 99) // 'ab'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## string.split / string.join / string.words {#split}
|
|
181
|
+
|
|
182
|
+
```cypher
|
|
183
|
+
RETURN string.split('a,b,c,d', ','); // ['a', 'b', 'c', 'd']
|
|
184
|
+
RETURN string.split('one two three', ' '); // ['one', 'two', 'three']
|
|
185
|
+
RETURN string.split('x', ','); // ['x']
|
|
186
|
+
RETURN string.split('p12', ''); // ['p', '1', '2']
|
|
187
|
+
RETURN string.join(['red', 'green'], ', '); // 'red, green'
|
|
188
|
+
RETURN string.words(' red green\tblue ') // ['red', 'green', 'blue']
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Empty input returns `['']`. An empty delimiter splits into Unicode code
|
|
192
|
+
points, not grapheme clusters (and `split('', '')` is `[]`): a
|
|
193
|
+
precomposed `é` stays one element, an `e` followed by a combining accent
|
|
194
|
+
becomes two.
|
|
195
|
+
|
|
196
|
+
A list of delimiters splits on any of them, as in Neo4j 5. Each is
|
|
197
|
+
literal text (never a regex), and at each position the first one in the
|
|
198
|
+
list that matches wins.
|
|
199
|
+
|
|
200
|
+
```cypher
|
|
201
|
+
RETURN split('a,b;c', [',', ';']); // ['a', 'b', 'c']
|
|
202
|
+
RETURN split('a--b-c', ['--', '-']) // ['a', 'b', 'c']
|
|
203
|
+
```
|
|
204
|
+
`string.words` uses Unicode whitespace and drops empty fields, which is
|
|
205
|
+
usually what you want for tokenizing human-entered text.
|
|
206
|
+
|
|
207
|
+
### Split + UNWIND
|
|
208
|
+
|
|
209
|
+
Turn comma-separated values into rows:
|
|
210
|
+
|
|
211
|
+
```cypher
|
|
212
|
+
UNWIND string.split('red,green,blue', ',') AS color
|
|
213
|
+
CREATE (:Swatch {color: color})
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Join values for display
|
|
217
|
+
|
|
218
|
+
`string.join(list, separator)` accepts strings, numbers, booleans, and
|
|
219
|
+
`null` values. `null` becomes an empty field.
|
|
220
|
+
|
|
221
|
+
```cypher
|
|
222
|
+
MATCH (u:User)
|
|
223
|
+
RETURN u.name, string.join(u.tags, ', ') AS tags_csv
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## string.reverse / value.reverse {#reverse}
|
|
227
|
+
|
|
228
|
+
Works on both strings and lists.
|
|
229
|
+
|
|
230
|
+
```cypher
|
|
231
|
+
RETURN string.reverse('hello'); // 'olleh'
|
|
232
|
+
RETURN value.reverse([1, 2, 3]) // [3, 2, 1]
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
`reverse(x)` is a compatibility alias for `value.reverse(x)`, which
|
|
236
|
+
works for both strings and lists. Use `string.reverse(s)` when you want
|
|
237
|
+
to be explicit that the input should be text.
|
|
238
|
+
|
|
239
|
+
## string.length / value.size {#stringlength--valuesize}
|
|
240
|
+
|
|
241
|
+
| Function | Measures |
|
|
242
|
+
|---|---|
|
|
243
|
+
| `string.length(s)` | Unicode code-point count |
|
|
244
|
+
| `value.size(s)` / `size(s)` | Polymorphic size helper; strings return their length |
|
|
245
|
+
| `path.length(p)` / `length(p)` | Hop count for paths, not a string helper |
|
|
246
|
+
|
|
247
|
+
```cypher
|
|
248
|
+
RETURN string.length('abc'); // 3
|
|
249
|
+
RETURN string.length('café'); // 4
|
|
250
|
+
RETURN value.size('abc') // 3
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
For paths, use [`path.length(p)`](../queries/paths.md#path-functions).
|
|
254
|
+
|
|
255
|
+
## string.is_blank {#stringis_blank}
|
|
256
|
+
|
|
257
|
+
`string.is_blank(s)` returns `true` when a string is empty or contains
|
|
258
|
+
only whitespace. It is useful for imports where a missing field arrives
|
|
259
|
+
as spaces instead of `null`.
|
|
260
|
+
|
|
261
|
+
```cypher
|
|
262
|
+
RETURN string.is_blank(' '); // true
|
|
263
|
+
RETURN string.is_blank('\t\n'); // true
|
|
264
|
+
RETURN string.is_blank(' data ') // false
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## string.pad_left / string.pad_right {#lpad--rpad}
|
|
268
|
+
|
|
269
|
+
`string.pad_left(str, length, padding)` / `string.pad_right(str, length, padding)` — pads to
|
|
270
|
+
the target length using the padding character repeated.
|
|
271
|
+
|
|
272
|
+
```cypher
|
|
273
|
+
RETURN string.pad_left('7', 3, '0'); // '007'
|
|
274
|
+
RETURN string.pad_right('7', 3, '0'); // '700'
|
|
275
|
+
RETURN string.pad_left('abc', 5, '.'); // '..abc'
|
|
276
|
+
RETURN string.pad_right('abc', 5, '.') // 'abc..'
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
If the input is already longer than `length`, it's returned unchanged.
|
|
280
|
+
|
|
281
|
+
### Fixed-width formatting
|
|
282
|
+
|
|
283
|
+
```cypher
|
|
284
|
+
MATCH (r:Record)
|
|
285
|
+
RETURN string.pad_left(toString(r.id), 6, '0') AS padded_id
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Encoding and Escaping
|
|
289
|
+
|
|
290
|
+
Use `string.slugify` for simple URL slugs, `string.escape` when embedding
|
|
291
|
+
text into another format, and URL helpers for query-string safe values.
|
|
292
|
+
|
|
293
|
+
```cypher
|
|
294
|
+
RETURN string.slugify('Hello, World! 2026'); // 'hello-world-2026'
|
|
295
|
+
RETURN string.escape('Tom & "Ada"', 'html'); // 'Tom & "Ada"'
|
|
296
|
+
RETURN string.escape('Tom & "Ada"', 'json'); // '"Tom & \"Ada\""'
|
|
297
|
+
RETURN string.url_encode('a b/c'); // 'a%20b%2Fc'
|
|
298
|
+
RETURN string.url_decode('a%20b%2Fc') // 'a b/c'
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
`string.escape` supports `'json'`, `'html'`, and `'cypher'` / `'lora'`.
|
|
302
|
+
`string.slugify` is intentionally conservative: it lowercases ASCII
|
|
303
|
+
letters and collapses non-alphanumeric runs to `-`.
|
|
304
|
+
|
|
305
|
+
## string.normalize {#normalize}
|
|
306
|
+
|
|
307
|
+
`string.normalize(s[, form])` applies Unicode normalization. The default
|
|
308
|
+
form is `'nfc'`. Supported forms are `'nfc'`, `'nfd'`, `'nfkc'`, and
|
|
309
|
+
`'nfkd'`.
|
|
310
|
+
|
|
311
|
+
```cypher
|
|
312
|
+
RETURN string.normalize('Café'); // 'Café' (NFC)
|
|
313
|
+
RETURN string.length(string.normalize('é', 'nfd')) // 2
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Normalize text before storing it when users may submit visually identical
|
|
317
|
+
strings in different Unicode forms. Pair with `string.lower` and
|
|
318
|
+
`string.trim` for stable email or slug comparisons.
|
|
319
|
+
|
|
320
|
+
## Type conversion
|
|
321
|
+
|
|
322
|
+
These helpers are kept for Cypher compatibility and quick scalar
|
|
323
|
+
parsing. For explicit typed construction, prefer casts:
|
|
324
|
+
`'2024-01-15'::DATE`, `{x: 1, y: 2}::POINT`,
|
|
325
|
+
`[1, 2, 3]::VECTOR<INTEGER>(3)`, or `CAST(value AS TYPE)`.
|
|
326
|
+
Use `TRY_CAST(value AS TYPE)` when invalid input should become `null`.
|
|
327
|
+
|
|
328
|
+
| Function | Accepts | Returns |
|
|
329
|
+
|---|---|---|
|
|
330
|
+
| `toString(x)` | any | `String`; `null` → `null` |
|
|
331
|
+
| `toInteger(x)` / `toIntegerOrNull(x)` | `Int`, `Float` (truncates), `String`, `Bool` | `Int`; `OrNull` form returns `null` on parse failure |
|
|
332
|
+
| `toFloat(x)` / `toFloatOrNull(x)` | `Int`, `Float`, `String` | `Float`; `OrNull` form returns `null` on parse failure |
|
|
333
|
+
| `toBoolean(x)` / `toBooleanOrNull(x)` | `Bool`, `String` (`"true"`/`"false"`), `Int` (0 / non-0) | `Bool`; `OrNull` form returns `null` on parse failure |
|
|
334
|
+
|
|
335
|
+
```cypher
|
|
336
|
+
RETURN toString(42); // '42'
|
|
337
|
+
RETURN toString(true); // 'true'
|
|
338
|
+
RETURN toString('2024-01-15'::DATE); // '2024-01-15'
|
|
339
|
+
|
|
340
|
+
RETURN toInteger('007'); // 7
|
|
341
|
+
RETURN toInteger(3.9); // 3 (truncates)
|
|
342
|
+
RETURN toInteger(true); // 1
|
|
343
|
+
RETURN toIntegerOrNull('not a number'); // null (parse fails)
|
|
344
|
+
|
|
345
|
+
RETURN toFloat('3.14'); // 3.14
|
|
346
|
+
RETURN toFloat(42); // 42.0
|
|
347
|
+
|
|
348
|
+
RETURN toBoolean('TRUE'); // true
|
|
349
|
+
RETURN toBoolean(0); // false
|
|
350
|
+
RETURN toBooleanOrNull('maybe') // null
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Safe conversion pattern
|
|
354
|
+
|
|
355
|
+
Combine with [`coalesce`](./overview.md#type-conversion-and-checking) for a
|
|
356
|
+
default on parse failure:
|
|
357
|
+
|
|
358
|
+
```cypher
|
|
359
|
+
MATCH (p:Product) RETURN coalesce(toInteger(p.stock), 0) AS stock
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
For imports where the target type is not one of the simple scalar helper
|
|
363
|
+
names, keep the conversion explicit:
|
|
364
|
+
|
|
365
|
+
```cypher
|
|
366
|
+
UNWIND $rows AS row
|
|
367
|
+
WITH row, TRY_CAST(row.shipped_on AS DATE) AS shipped_on
|
|
368
|
+
WHERE shipped_on IS NOT NULL
|
|
369
|
+
CREATE (:Shipment {id: row.id, shipped_on: shipped_on})
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## string.prefix_end {#stringprefix_end}
|
|
373
|
+
|
|
374
|
+
The smallest string greater than every string that starts with the
|
|
375
|
+
argument: its last character that can be incremented is, and what
|
|
376
|
+
follows is dropped. `null` when there is none (the empty string, or one
|
|
377
|
+
of only U+10FFFF characters). `x STARTS WITH s` is the range
|
|
378
|
+
`s <= x < string.prefix_end(s)`, which is how a RANGE index answers
|
|
379
|
+
`STARTS WITH`.
|
|
380
|
+
|
|
381
|
+
```cypher
|
|
382
|
+
RETURN string.prefix_end('ab') // 'ac'
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## String operators (in [`WHERE`](../queries/where.md)) {#string-operators-in-where}
|
|
386
|
+
|
|
387
|
+
Covered in the [`WHERE`](../queries/where.md#string-matching) page —
|
|
388
|
+
included here for completeness:
|
|
389
|
+
|
|
390
|
+
| Operator | Case-sensitive | Description |
|
|
391
|
+
|---|---|---|
|
|
392
|
+
| `STARTS WITH` | yes | Prefix match |
|
|
393
|
+
| `ENDS WITH` | yes | Suffix match |
|
|
394
|
+
| `CONTAINS` | yes | Substring match |
|
|
395
|
+
| `=~` | yes | Regex match (Rust `regex`, RE2-style — no backreferences) |
|
|
396
|
+
|
|
397
|
+
```cypher
|
|
398
|
+
MATCH (u:User) WHERE u.email ENDS WITH '@loradb.com' RETURN u;
|
|
399
|
+
MATCH (u:User) WHERE string.lower(u.email) =~ '.*@loradb\\.com$' RETURN u;
|
|
400
|
+
MATCH (u:User) WHERE u.name CONTAINS 'Admin' RETURN u
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Regex vs CONTAINS
|
|
404
|
+
|
|
405
|
+
Regex is more expressive but slower and strict-anchored (`=~ 'foo'`
|
|
406
|
+
matches only the full string `foo`). Prefer `CONTAINS` for simple
|
|
407
|
+
substring matches.
|
|
408
|
+
|
|
409
|
+
## Common patterns
|
|
410
|
+
|
|
411
|
+
### Slugify
|
|
412
|
+
|
|
413
|
+
```cypher
|
|
414
|
+
WITH 'Hello, World! 2024' AS raw
|
|
415
|
+
RETURN string.slugify(raw) AS slug
|
|
416
|
+
// 'hello-world-2024'
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
For international slugs, normalize first and decide host-side whether to
|
|
420
|
+
transliterate non-ASCII characters.
|
|
421
|
+
|
|
422
|
+
### Initials
|
|
423
|
+
|
|
424
|
+
```cypher
|
|
425
|
+
MATCH (p:Person) WHERE p.name IS NOT NULL
|
|
426
|
+
RETURN p.name,
|
|
427
|
+
reduce(acc = '', part IN string.split(p.name, ' ') |
|
|
428
|
+
acc + string.prefix(part, 1)) AS initials
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
### Domain from email
|
|
432
|
+
|
|
433
|
+
```cypher
|
|
434
|
+
MATCH (u:User) WHERE u.email CONTAINS '@'
|
|
435
|
+
RETURN u.email,
|
|
436
|
+
string.slice(u.email, value.size(string.split(u.email, '@')[0]) + 1) AS domain
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Normalise for comparison
|
|
440
|
+
|
|
441
|
+
```cypher
|
|
442
|
+
MATCH (u:User)
|
|
443
|
+
WHERE string.lower(string.trim(u.email)) = string.lower(string.trim($candidate))
|
|
444
|
+
RETURN u
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Join a list into a string
|
|
448
|
+
|
|
449
|
+
```cypher
|
|
450
|
+
MATCH (u:User)
|
|
451
|
+
RETURN u.name, string.join(u.tags, ', ') AS tags_csv
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
For conditional joins or per-element formatting, use
|
|
455
|
+
[`reduce`](./list.md#reduce) so each element can be transformed before it
|
|
456
|
+
is appended.
|
|
457
|
+
|
|
458
|
+
### Parse `key=value` pairs
|
|
459
|
+
|
|
460
|
+
```cypher
|
|
461
|
+
WITH 'a=1;b=2;c=3' AS s
|
|
462
|
+
RETURN [pair IN string.split(s, ';') |
|
|
463
|
+
{key: string.split(pair, '=')[0], value: string.split(pair, '=')[1]}
|
|
464
|
+
] AS parsed
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
Values are strings — wrap each parsed value with
|
|
468
|
+
[`toInteger`](./string.md#type-conversion) if you need numeric
|
|
469
|
+
types.
|
|
470
|
+
|
|
471
|
+
### Truncate for preview
|
|
472
|
+
|
|
473
|
+
```cypher
|
|
474
|
+
MATCH (p:Post)
|
|
475
|
+
RETURN p.id,
|
|
476
|
+
CASE WHEN string.length(p.body) > 100
|
|
477
|
+
THEN string.prefix(p.body, 97) + '...'
|
|
478
|
+
ELSE p.body
|
|
479
|
+
END AS preview
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
The conditional here is a [`CASE`](../queries/return-with.md#case-expressions)
|
|
483
|
+
expression — LoraDB's ternary. See that page for the full reference.
|
|
484
|
+
|
|
485
|
+
## Limitations
|
|
486
|
+
|
|
487
|
+
- `string.lower` / `string.upper` use Unicode case mapping, not
|
|
488
|
+
locale-specific case folding. Turkish dotted/dotless `i` and similar
|
|
489
|
+
locale-sensitive cases should still be handled host-side when exact
|
|
490
|
+
locale behavior matters.
|
|
491
|
+
- `string.find` returns byte offsets. Use `string.slice` for code-point
|
|
492
|
+
slicing once you already know the desired character positions.
|
|
493
|
+
- `string.normalize` handles Unicode normalization forms, but it is not
|
|
494
|
+
a locale-aware collation or fuzzy matching function.
|
|
495
|
+
- Use `string.length` when you need Unicode code-point counts.
|
|
496
|
+
|
|
497
|
+
## See also
|
|
498
|
+
|
|
499
|
+
- [**Scalars → String**](../data-types/scalars.md#string) — literal syntax and comparison.
|
|
500
|
+
- [**WHERE → String matching**](../queries/where.md#string-matching).
|
|
501
|
+
- [**Lists**](../data-types/lists-and-maps.md#lists) — `string.split` returns a list.
|
|
502
|
+
- [**Functions → Overview**](./overview.md) — `toString`, `toInteger`, etc.
|