REGEX_SPLIT()
All functions > STRING > REGEX_SPLIT()
Splits a string by a regular expression pattern and returns the parts between matches as an array.
Signatures
Returns: Array of substrings between matches; single-element array containing the original string when there is no match; NULL if the haystack is NULL
REGEX_SPLIT(string: VARCHAR, pattern: VARCHAR) → ARRAYVARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to split |
pattern | VARCHAR | Yes | Regular expression pattern to split on |
Notes
- Returns the parts between matches, not the matches themselves; use
REGEX_EXTRACT_ALLto get the matched text instead - Consecutive matches (or a match at the start/end of the string) produce empty strings in the result array
- Not available on every deployment target (unsupported targets fail translation)
See also
Examples
FeatureQL
SELECT
f1 := REGEX_SPLIT('abc123def456ghi', '[0-9]+'), -- Split by digit groups
f2 := REGEX_SPLIT('one::two:::three', ':+'), -- Split by one or more colons
f3 := REGEX_SPLIT('hello world foo', '\s+'), -- Split by whitespace
f4 := REGEX_SPLIT(',a,b,', ','), -- Leading and trailing delimiters produce empty strings
f5 := REGEX_SPLIT('no match here', '[0-9]+'), -- No match returns original string in array
f6 := REGEX_SPLIT(NULL(VARCHAR), ',') -- NULL haystack
;Result
| f1 ARRAY | f2 ARRAY | f3 ARRAY | f4 VARCHAR | f5 ARRAY | f6 ARRAY |
|---|---|---|---|---|---|
| [abc, def, ghi] | [one, two, three] | [hello, world, foo] | [(empty), a, b, (empty)] | [no match here] | NULL |
On this page