Replaces all occurrences of a substring matching a regular expression pattern with a replacement string.
flex.text.replace(string, regex, replacement)| Parameter | Type | Required | Description |
|---|---|---|---|
string |
string | Yes | The string to perform replacements on |
regex |
string | Yes | The regular expression pattern to match (applied globally) |
replacement |
string | Yes | The string to replace matches with |
Type: string
A new string with all pattern matches replaced by the replacement string. Returns null if input string is null.
RETURN flex.text.replace('hello world', 'world', 'universe') AS resultOutput:
result
--------------
hello universe
WITH 'Phone: (555) 123-4567' AS phone
RETURN flex.text.replace(phone, '[^0-9]', '') AS cleanedOutput:
cleaned
-----------
5551234567
MATCH (c:Comment)
WITH c, flex.text.replace(c.text, '<[^>]+>', '') AS sanitized
RETURN sanitized AS cleanCommentWITH ' Multiple spaces here ' AS text
RETURN flex.text.replace(text, '\\s+', ' ') AS normalizedOutput:
normalized
-------------------------
Multiple spaces here
- Returns
nullif input string isnull - Uses global replacement (replaces all occurrences)
- Pattern is treated as a regular expression
- Useful for data cleaning, sanitization, and text transformation
- Can use regex patterns for complex replacements
- text.regexGroups - Extract matches with capture groups
- text.indexOf - Find substring position
- text.format - Format strings with placeholders