Request a demo

BigQuery reference

BigQuery string functions

String functions in BigQuery split, search, replace, pad and format STRING values, and most also accept BYTES. Positions are 1-based, and the REGEXP_ functions use the RE2 regular expression syntax.

Functions in this category

FunctionWhat it does
CONCATCONCAT joins two or more values into one STRING (or BYTES): CONCAT(first_name, ' ', last_name).
CONTAINS_SUBSTRCONTAINS_SUBSTR(expression, 'text') returns TRUE if the text appears anywhere in the value, ignoring case and Unicode differences.
ENDS_WITHENDS_WITH(value, suffix) returns TRUE if a string ends with suffix: ENDS_WITH(file_name, '.parquet') finds Parquet files.
FORMATFORMAT(pattern, values...) builds a string with printf-style specifiers: FORMAT('%.2f', 3.14159) returns 3.14, FORMAT("%'d", 1234567) returns 1,234,567 and FORMAT('%s has %d orders', name, n) fills in text.
INITCAPINITCAP(value[, delimiters]) capitalizes the first letter of each word and lowercases the rest: INITCAP('mary-jane SMITH') returns Mary-Jane Smith.
INSTRINSTR(value, subvalue[, position[, occurrence]]) returns the 1-based position of a substring, optionally starting at a given position or finding the nth match.
LEFTLEFT(value, length) returns the first length characters of a string (or bytes of a BYTES value): LEFT('4111111111111111', 4) returns 4111.
LENGTHLENGTH(value) returns the number of characters in a STRING, or the number of bytes in a BYTES value.
LOWERLOWER(value) converts a string to lowercase using Unicode case rules: LOWER('Ana@Example.COM') returns ana@example.com.
LPADLPAD(value, length[, pattern]) pads a string on the left to a fixed length: LPAD('42', 6, '0') returns 000042.
LTRIMLTRIM(value[, characters]) removes leading whitespace, or every leading character found in the characters set: LTRIM('000123', '0') returns 123.
REGEXP_CONTAINSREGEXP_CONTAINS(value, regex) returns TRUE if any part of the string matches an RE2 regular expression: REGEXP_CONTAINS(email, r'@example\.(com|org)$').
REGEXP_EXTRACTREGEXP_EXTRACT(value, regex) returns the first substring that matches an RE2 regular expression, or the capture group if the pattern has one: REGEXP_EXTRACT(note, r'\d+') pulls the first number from text.
REGEXP_EXTRACT_ALLREGEXP_EXTRACT_ALL(value, regex) returns an ARRAY of every non-overlapping match of an RE2 regular expression: REGEXP_EXTRACT_ALL(text, r'#(\w+)') returns all hashtags.
REGEXP_REPLACEREGEXP_REPLACE(value, regex, replacement) replaces every match of an RE2 regular expression: REGEXP_REPLACE(phone, r'[^0-9]', '') keeps only digits.
REPLACEREPLACE(value, from, to) replaces every occurrence of a substring: REPLACE(phone, ' ', '') removes all spaces.
REVERSEREVERSE(value) returns a STRING with its characters in reverse order, or a BYTES value with its bytes reversed: REVERSE('stressed') returns desserts.
RIGHTRIGHT(value, length) returns the last length characters of a string (or bytes of a BYTES value): RIGHT('4111111111111111', 4) returns 1111.
RPADRPAD(value, length[, pattern]) pads a string on the right to a fixed length: RPAD('SKU', 8, '.') returns SKU.....
RTRIMRTRIM(value[, characters]) removes trailing whitespace, or every trailing character found in the characters set: RTRIM('12.500', '0') returns 12.5.
SOUNDEXSOUNDEX(value) returns a four-character phonetic code (a letter and three digits) for how a word sounds in English: SOUNDEX('Smith') and SOUNDEX('Smyth') both return S530.
SPLITSPLIT breaks a string into an ARRAY<STRING> on a delimiter: SPLIT('a,b,c', ',') returns [a, b, c].
STARTS_WITHSTARTS_WITH(value, prefix) returns TRUE if a string begins with prefix: STARTS_WITH(table_name, 'tmp_') is TRUE for tmp_orders.
STRPOSSTRPOS(value, subvalue) returns the 1-based position of the first occurrence of subvalue, or 0 if it isn't found: STRPOS('ana@example.com', '@') returns 4.
SUBSTRSUBSTR(value, position[, length]) returns part of a string: SUBSTR('INV-2026-00042', 5, 4) returns 2026.
TRANSLATETRANSLATE(value, source_chars, target_chars) replaces each character in source_chars with the character at the same position in target_chars, and deletes source characters that have no counterpart: TRANSLATE(phone, '()- ', '') strips four characters in one call.
TRIMTRIM(value[, characters]) removes leading and trailing whitespace from a string, or every leading and trailing character found in the characters set: TRIM('xxapplexx', 'x') returns apple.
UPPERUPPER(value) converts a string to uppercase using Unicode case rules: UPPER('de-be') returns DE-BE.

More of the BigQuery reference

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.