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
| Function | What it does |
|---|---|
| CONCAT | CONCAT joins two or more values into one STRING (or BYTES): CONCAT(first_name, ' ', last_name). |
| CONTAINS_SUBSTR | CONTAINS_SUBSTR(expression, 'text') returns TRUE if the text appears anywhere in the value, ignoring case and Unicode differences. |
| ENDS_WITH | ENDS_WITH(value, suffix) returns TRUE if a string ends with suffix: ENDS_WITH(file_name, '.parquet') finds Parquet files. |
| FORMAT | FORMAT(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. |
| INITCAP | INITCAP(value[, delimiters]) capitalizes the first letter of each word and lowercases the rest: INITCAP('mary-jane SMITH') returns Mary-Jane Smith. |
| INSTR | INSTR(value, subvalue[, position[, occurrence]]) returns the 1-based position of a substring, optionally starting at a given position or finding the nth match. |
| LEFT | LEFT(value, length) returns the first length characters of a string (or bytes of a BYTES value): LEFT('4111111111111111', 4) returns 4111. |
| LENGTH | LENGTH(value) returns the number of characters in a STRING, or the number of bytes in a BYTES value. |
| LOWER | LOWER(value) converts a string to lowercase using Unicode case rules: LOWER('Ana@Example.COM') returns ana@example.com. |
| LPAD | LPAD(value, length[, pattern]) pads a string on the left to a fixed length: LPAD('42', 6, '0') returns 000042. |
| LTRIM | LTRIM(value[, characters]) removes leading whitespace, or every leading character found in the characters set: LTRIM('000123', '0') returns 123. |
| REGEXP_CONTAINS | REGEXP_CONTAINS(value, regex) returns TRUE if any part of the string matches an RE2 regular expression: REGEXP_CONTAINS(email, r'@example\.(com|org)$'). |
| REGEXP_EXTRACT | REGEXP_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_ALL | REGEXP_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_REPLACE | REGEXP_REPLACE(value, regex, replacement) replaces every match of an RE2 regular expression: REGEXP_REPLACE(phone, r'[^0-9]', '') keeps only digits. |
| REPLACE | REPLACE(value, from, to) replaces every occurrence of a substring: REPLACE(phone, ' ', '') removes all spaces. |
| REVERSE | REVERSE(value) returns a STRING with its characters in reverse order, or a BYTES value with its bytes reversed: REVERSE('stressed') returns desserts. |
| RIGHT | RIGHT(value, length) returns the last length characters of a string (or bytes of a BYTES value): RIGHT('4111111111111111', 4) returns 1111. |
| RPAD | RPAD(value, length[, pattern]) pads a string on the right to a fixed length: RPAD('SKU', 8, '.') returns SKU..... |
| RTRIM | RTRIM(value[, characters]) removes trailing whitespace, or every trailing character found in the characters set: RTRIM('12.500', '0') returns 12.5. |
| SOUNDEX | SOUNDEX(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. |
| SPLIT | SPLIT breaks a string into an ARRAY<STRING> on a delimiter: SPLIT('a,b,c', ',') returns [a, b, c]. |
| STARTS_WITH | STARTS_WITH(value, prefix) returns TRUE if a string begins with prefix: STARTS_WITH(table_name, 'tmp_') is TRUE for tmp_orders. |
| STRPOS | STRPOS(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. |
| SUBSTR | SUBSTR(value, position[, length]) returns part of a string: SUBSTR('INV-2026-00042', 5, 4) returns 2026. |
| TRANSLATE | TRANSLATE(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. |
| TRIM | TRIM(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. |
| UPPER | UPPER(value) converts a string to uppercase using Unicode case rules: UPPER('de-be') returns DE-BE. |
More of the BigQuery reference
Date functionsDatetime functionsTimestamp functionsAggregate functionsWindow functionsArray functionsJSON functionsConversion functionsConditional expressionsMathematical functionsHash and utility functionsQuery syntaxDDL statementsDML statementsScripting and data movementINFORMATION_SCHEMAError messagesBigQuery pricingPricing calculator
