Text Functions
concat
concat(value1, value2, ...)
concat('Hello', ' ', 'World') // -> Hello World
concat('Hello', ' ', 'World', '!') // -> Hello World!
Description
This function concatenates multiple strings into a single string.
Return type
Text
find
find(text, substring)
Description
Returns the position of the first occurrence of a substring within a text string. The returned position is a positive number starting from 1. Returns 0 if the substring is not found.
Aliases
find_index
Return type
Number
Examples
find('Hello World', 'World') // Returns 7
find('Hello World', 'o') // Returns 5
find('Hello World', 'Universe') // Returns 0
left
left(text, length)
Description
Returns the leftmost characters of a text string, up to the specified length.
Return type
Text
Examples
left('Hello World', 5) // Returns 'Hello'
left('Hello', 10) // Returns 'Hello'
right
right(text, length)
Description
Returns the rightmost characters of a text string, up to the specified length.
Return type
Text
Examples
right('Hello World', 5) // Returns 'World'
right('Hello', 10) // Returns 'Hello'
mid
mid(text, start, length)
Description
Extracts a substring of a specified length from a text string, starting at a given position.
text
: the text stringstart
: the position where the extraction starts. It must be a positive number. The first position in the text is 1.length
: the (maximum) length of the substring
Return type
Text
Examples
mid('Hello World', 7, 5) // Returns 'World'
mid('Hello World', 3, 3) // Returns 'llo'
len
len(text)
Description
Returns the length of a text string (number of characters).
Return type
Number
Examples
len('Hello World') // Returns 11
len('') // Returns 0
lpad
lpad(text, length, pad_string)
Description
Pads the left side of a text string with a specified pad string until it reaches the specified length. If the text is already longer than the length it will be truncated.
Return type
Text
Examples
lpad('Hello', 10, ' ') // Returns ' Hello'
lpad('Hello', 10, 'abc') // Returns 'abcabHello'
lpad('Hello World', 10, '0') // Returns 'Hello Worl'
rpad
rpad(text, length, pad_string)
Description
Pads the right side of a text string with a specified pad string until it reaches the specified length. If the text is already longer than the length it will be truncated.
Return type
Text
Examples
rpad('Hello', 10, ' ') // Returns 'Hello '
rpad('Hello', 10, 'abc') // Returns 'Helloabcab'
rpad('Hello World', 10, '0') // Returns 'Hello Worl'
lower
lower(text)
Description
Converts a text string to lowercase.
Return type
Text
Examples
lower('Hello World') // Returns 'hello world'
lower('HELLO') // Returns 'hello'
upper
upper(text)
Description
Converts a text string to uppercase.
Return type
Text
Examples
upper('Hello World') // Returns 'HELLO WORLD'
upper('hello') // Returns 'HELLO'
trim
trim(text)
Description
Removes leading and trailing whitespace from a text string.
Return type
Text
Examples
trim(' Hello World ') // Returns 'Hello World'
trim(' Hello ') // Returns 'Hello'
ltrim
ltrim(text)
Description
Removes leading whitespace from a text string.
Return type
Text
Examples
ltrim(' Hello World') // Returns 'Hello World'
ltrim(' Hello ') // Returns 'Hello '
rtrim
rtrim(text)
Description
Removes trailing whitespace from a text string.
Return type
Text
Examples
rtrim('Hello World ') // Returns 'Hello World'
rtrim(' Hello ') // Returns ' Hello'
regexp_extract
regexp_extract(text, regex, [occurrence], [group: _group], [flags: _flags])
Description
Extracts a substring from a text string that matches a regular expression pattern.
Return type
Text
Examples
regexp_extract('Product123', '[0-9]+') // Returns '123'
regexp_extract('Hello World Example', '\\w+', 2) // Returns 'World'
regexp_extract('Hello World', 'hello', flags: 'i') // Returns 'Hello'
regexp_extract('Product123.3', '(\\d+)\\.\\d+', group: 1) // Returns '123'
Parameters
text
: The text string to search withinregex
: The regular expression pattern to match (exact regex syntax depends on the database)occurrence
(optional): The position of the occurrence to return. E.g.1
means return the first occurrence that matches the regex.group
(optional): The capture group to extract from the matched occurrence (BigQuery does not support this)flags
(optional): Flags to modify the behavior of the regular expression matching (supported flags depend on the database)
Notes
This function is not supported in the following databases:
- SQL Server
For BigQuery, the group
parameter is not supported. BigQuery will automatically extract the first capture group if one exists in the regex. BigQuery will throw an error if the regex has multiple capture groups. To use grouping without extracting a specific group, utilize non-capture groups.
regexp_match
regexp_match(text, regex, [flags: _flags])
Description
Checks if a text string matches a regular expression pattern.
Return type
Truefalse
Examples
regexp_match('Product123', '[0-9]+') // Returns true
regexp_match('Hello World', '^hello', flags: 'i') // Returns true
Parameters
text
: The text string to search withinregex
: The regular expression pattern to match (exact regex syntax depends on the database)flags
(optional): Flags to modify the behavior of the regular expression matching (supported flags depend on the database)
Notes
This function is not supported in the following databases:
- SQL Server
regexp_replace
regexp_replace(text, regex, substitute, [flags: _flags])
Description
Replaces substrings in a text that match a regular expression pattern with a specified replacement text.
Return type
Text
Examples
regexp_replace('Product123', '[0-9]+', 'X') // Returns 'ProductX'
regexp_replace('Hello World', '\\s+', ' ') // Returns 'Hello World'
regexp_replace('John Doe', '(\\w+) (\\w+)', '\\2, \\1') // Returns 'Doe, John'
Parameters
text
: The text string to perform the replacement inregex
: The regular expression pattern to match (exact regex syntax depends on the database)substitute
: The replacement string. You can use backreferences like\\1
or$1
(depending on the specific database) to refer to captured groups in the regexflags
(optional): Flags to modify the behavior of the regular expression matching (supported flags depend on the database)
Notes
This function is not supported in the following databases:
- SQL Server
replace
replace(text, old_substring, new_substring)
Description
Replaces all occurrences of a substring within a text string with a new substring.
Return type
Text
Examples
replace('Hello World', 'World', 'Universe') // Returns 'Hello Universe'
replace('Hello World', 'o', '0') // Returns 'Hell0 W0rld'
split_part
split_part(text, delimiter, part_number)
Description
Splits a text string into parts based on a delimiter and returns the specified part.
part_number
is the number of the part to return, starting from 1. It must be a positive number.
Return type
Text
Examples
split_part('apple,banana,cherry', ',', 2) // Returns 'banana'
split_part('Hello World', ' ', 1) // Returns 'Hello'
Notes
This function is not supported in the following databases:
- Microsoft SQL Server