# BigQuery String Functions: Syntax and Examples | Masthead

String functions in BigQuery split, search, replace, pad and format STRING values, and most also accept BYTES. 28 string functions with syntax, runnable examples, common mistakes and cost notes.

> For the index of this section of the site, see [llms.txt](https://mastheadata.com/llms.txt)

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](https://mastheadata.com/bigquery/functions/concat.md) | CONCAT joins two or more values into one STRING (or BYTES): CONCAT(first\_name, ' ', last\_name). |
| [CONTAINS\SUBSTR](https://mastheadata.com/bigquery/functions/contains-substr.md) | CONTAINS\_SUBSTR(expression, 'text') returns TRUE if the text appears anywhere in the value, ignoring case and Unicode differences. |
| [ENDS\WITH](https://mastheadata.com/bigquery/functions/ends-with.md) | ENDS\_WITH(value, suffix) returns TRUE if a string ends with suffix: ENDS\_WITH(file\_name, '.parquet') finds Parquet files. |
| [FORMAT](https://mastheadata.com/bigquery/functions/format.md) | 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](https://mastheadata.com/bigquery/functions/initcap.md) | INITCAP(value\[, delimiters\]) capitalizes the first letter of each word and lowercases the rest: INITCAP('mary-jane SMITH') returns Mary-Jane Smith. |
| [INSTR](https://mastheadata.com/bigquery/functions/instr.md) | 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](https://mastheadata.com/bigquery/functions/left.md) | LEFT(value, length) returns the first length characters of a string (or bytes of a BYTES value): LEFT('4111111111111111', 4) returns 4111. |
| [LENGTH](https://mastheadata.com/bigquery/functions/length.md) | LENGTH(value) returns the number of characters in a STRING, or the number of bytes in a BYTES value. |
| [LOWER](https://mastheadata.com/bigquery/functions/lower.md) | LOWER(value) converts a string to lowercase using Unicode case rules: LOWER('Ana@Example.COM') returns ana@example.com. |
| [LPAD](https://mastheadata.com/bigquery/functions/lpad.md) | LPAD(value, length\[, pattern\]) pads a string on the left to a fixed length: LPAD('42', 6, '0') returns 000042. |
| [LTRIM](https://mastheadata.com/bigquery/functions/ltrim.md) | LTRIM(value\[, characters\]) removes leading whitespace, or every leading character found in the characters set: LTRIM('000123', '0') returns 123. |
| [REGEXP\CONTAINS](https://mastheadata.com/bigquery/functions/regexp-contains.md) | 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](https://mastheadata.com/bigquery/functions/regexp-extract.md) | 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](https://mastheadata.com/bigquery/functions/regexp-extract-all.md) | 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](https://mastheadata.com/bigquery/functions/regexp-replace.md) | REGEXP\_REPLACE(value, regex, replacement) replaces every match of an RE2 regular expression: REGEXP\_REPLACE(phone, r'\[^0-9\]', '') keeps only digits. |
| [REPLACE](https://mastheadata.com/bigquery/functions/replace.md) | REPLACE(value, from, to) replaces every occurrence of a substring: REPLACE(phone, ' ', '') removes all spaces. |
| [REVERSE](https://mastheadata.com/bigquery/functions/reverse.md) | REVERSE(value) returns a STRING with its characters in reverse order, or a BYTES value with its bytes reversed: REVERSE('stressed') returns desserts. |
| [RIGHT](https://mastheadata.com/bigquery/functions/right.md) | RIGHT(value, length) returns the last length characters of a string (or bytes of a BYTES value): RIGHT('4111111111111111', 4) returns 1111. |
| [RPAD](https://mastheadata.com/bigquery/functions/rpad.md) | RPAD(value, length\[, pattern\]) pads a string on the right to a fixed length: RPAD('SKU', 8, '.') returns SKU..... |
| [RTRIM](https://mastheadata.com/bigquery/functions/rtrim.md) | RTRIM(value\[, characters\]) removes trailing whitespace, or every trailing character found in the characters set: RTRIM('12.500', '0') returns 12.5. |
| [SOUNDEX](https://mastheadata.com/bigquery/functions/soundex.md) | 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](https://mastheadata.com/bigquery/functions/split.md) | SPLIT breaks a string into an ARRAY<STRING> on a delimiter: SPLIT('a,b,c', ',') returns \[a, b, c\]. |
| [STARTS\WITH](https://mastheadata.com/bigquery/functions/starts-with.md) | STARTS\_WITH(value, prefix) returns TRUE if a string begins with prefix: STARTS\_WITH(table\_name, 'tmp\_') is TRUE for tmp\_orders. |
| [STRPOS](https://mastheadata.com/bigquery/functions/strpos.md) | 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](https://mastheadata.com/bigquery/functions/substr.md) | SUBSTR(value, position\[, length\]) returns part of a string: SUBSTR('INV-2026-00042', 5, 4) returns 2026. |
| [TRANSLATE](https://mastheadata.com/bigquery/functions/translate.md) | 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](https://mastheadata.com/bigquery/functions/trim.md) | 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](https://mastheadata.com/bigquery/functions/upper.md) | UPPER(value) converts a string to uppercase using Unicode case rules: UPPER('de-be') returns DE-BE. |

## More of the BigQuery reference

[Date functions](https://mastheadata.com/bigquery/date-functions.md)[Datetime functions](https://mastheadata.com/bigquery/datetime-functions.md)[Timestamp functions](https://mastheadata.com/bigquery/timestamp-functions.md)[Aggregate functions](https://mastheadata.com/bigquery/aggregate-functions.md)[Window functions](https://mastheadata.com/bigquery/window-functions.md)[Array functions](https://mastheadata.com/bigquery/array-functions.md)[JSON functions](https://mastheadata.com/bigquery/json-functions.md)[Conversion functions](https://mastheadata.com/bigquery/conversion-functions.md)[Conditional expressions](https://mastheadata.com/bigquery/conditional-expressions.md)[Mathematical functions](https://mastheadata.com/bigquery/math-functions.md)[Hash and utility functions](https://mastheadata.com/bigquery/utility-functions.md)[Query syntax](https://mastheadata.com/bigquery/query-syntax.md)[DDL statements](https://mastheadata.com/bigquery/ddl.md)[DML statements](https://mastheadata.com/bigquery/dml.md)[Scripting and data movement](https://mastheadata.com/bigquery/scripting.md)[INFORMATION\SCHEMA](https://mastheadata.com/bigquery/information-schema-views.md)[Error messages](https://mastheadata.com/bigquery/errors.md)[BigQuery pricing](https://mastheadata.com/bigquery/pricing.md)[Pricing calculator](https://mastheadata.com/bigquery/pricing-calculator.md)
---

## Other pages in BigQuery Reference

> For the full index of this section, see [BigQuery Reference](https://mastheadata.com/llms/llms-bigquery-reference.txt).

- [BigQuery Aggregate Functions: COUNT, SUM, STRING_AGG and More | Masthead](https://mastheadata.com/bigquery/aggregate-functions.md): Aggregate functions collapse many rows into one value per group. 16 aggregate functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Array Functions: UNNEST, ARRAY_AGG and More | Masthead](https://mastheadata.com/bigquery/array-functions.md): ARRAY is a first-class type in BigQuery: nested and repeated fields are how BigQuery avoids joins. 11 array functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conditional Expressions: CASE, IF, COALESCE, IFNULL | Masthead](https://mastheadata.com/bigquery/conditional-expressions.md): Conditional expressions choose a value based on a condition or on NULLs. 5 conditional expressions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Conversion Functions: CAST and SAFE_CAST | Masthead](https://mastheadata.com/bigquery/conversion-functions.md): Conversion functions change a value from one type to another. 3 conversion functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Cost Queries: SQL to Find and Cut BigQuery Spend | Masthead](https://mastheadata.com/bigquery/cost-queries.md): 20 ready-to-run SQL queries for BigQuery cost: the most expensive queries, cost by user, project, label, dbt model and dashboard, slot usage, storage cost, unused and dead-end tables.
- [BigQuery Date Functions: Syntax, Examples and Gotchas | Masthead](https://mastheadata.com/bigquery/date-functions.md): DATE functions in BigQuery (GoogleSQL) build, shift, truncate, compare and format calendar dates. 14 date functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Datetime Functions: Syntax and Examples | Masthead](https://mastheadata.com/bigquery/datetime-functions.md): DATETIME is a civil date and time with no time zone: what a wall clock shows. 8 datetime functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DDL: CREATE TABLE, Partitioning, Clustering and Views | Masthead](https://mastheadata.com/bigquery/ddl.md): Data definition language creates and changes tables, views, materialized views and functions. 8 DDL statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery DML: INSERT, UPDATE, DELETE and MERGE | Masthead](https://mastheadata.com/bigquery/dml.md): Data manipulation language changes table rows. 5 DML statements with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Error Messages: Causes and Fixes | Masthead](https://mastheadata.com/bigquery/errors.md): 51 BigQuery error messages explained: what each one means, why it happens and how to fix it, from "Resources exceeded" and quota errors to permissions, DML conflicts and failed loads.
- [BigQuery Functions List: Syntax and Examples for Every Function | Masthead](https://mastheadata.com/bigquery/functions.md): All 143 BigQuery SQL functions we cover, by category: date, timestamp, string, array, JSON, aggregate, window and more. Each with syntax, runnable examples, common mistakes and cost notes.
- [GA4 BigQuery Export: SQL Queries for Sessions, Users, Events and Revenue | Masthead](https://mastheadata.com/bigquery/ga4.md): 28 SQL recipes for the GA4 BigQuery export: unnest event_params, sessions, users, traffic sources, engagement, ecommerce, retention, and how to keep the queries cheap. Every one runs on Google's public GA4 sample.
- [BigQuery INFORMATION_SCHEMA: Jobs, Tables, Storage and Costs | Masthead](https://mastheadata.com/bigquery/information-schema-views.md): INFORMATION_SCHEMA views expose BigQuery metadata as tables you can query: jobs, slots, bytes billed, tables, columns and storage. 2 INFORMATION_SCHEMA with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery JSON Functions: JSON_VALUE, JSON_QUERY and More | Masthead](https://mastheadata.com/bigquery/json-functions.md): BigQuery reads JSON stored as STRING or as the native JSON type. 14 JSON functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Math Functions: ROUND, SAFE_DIVIDE, MOD and More | Masthead](https://mastheadata.com/bigquery/math-functions.md): Mathematical functions round, divide, bucket and transform numbers. 15 mathematical functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Pricing Calculator: On-Demand vs Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing-calculator.md): Free BigQuery pricing calculator: compare on-demand ($6.25 per TiB) with Standard, Enterprise and Enterprise Plus editions per slot-hour, and logical vs physical storage billing, using your own numbers from INFORMATION_SCHEMA.
- [BigQuery Pricing Explained (2026): On-Demand, Editions and Storage | Masthead](https://mastheadata.com/bigquery/pricing.md): BigQuery bills compute and storage separately. Compute is on-demand at $6.25 per TiB scanned (the first 1 TiB a month is free) or capacity-based with editions from $0.04 per slot-hour. Storage costs $0.02 per GiB a month for active data and $0.01 for data unchanged for 90 days (US, logical).
- [BigQuery Public Datasets: Sizes, Tables and What They Cost to Query | Masthead](https://mastheadata.com/bigquery/public-datasets.md): 40 BigQuery public datasets with their real table sizes and what querying them costs: GitHub, Stack Overflow, Wikipedia, Google Trends, GA4 sample, NOAA weather, taxi trips, crypto and more, with cheap example queries.
- [BigQuery Query Syntax: QUALIFY, PIVOT, CTEs, JOINs and More | Masthead](https://mastheadata.com/bigquery/query-syntax.md): The clauses that shape a GoogleSQL query in BigQuery: CTEs, joins, set operations, PIVOT, QUALIFY and SELECT * EXCEPT. 11 query syntax with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Scripting: Variables, Loops, Dynamic SQL, LOAD and EXPORT | Masthead](https://mastheadata.com/bigquery/scripting.md): Multi-statement queries let you declare variables, loop, branch and build SQL at run time, and LOAD DATA and EXPORT DATA move data in and out of BigQuery from SQL.. 5 scripting and data movement with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery SQL Syntax: Statements, Clauses, DDL and DML | Masthead](https://mastheadata.com/bigquery/sql.md): BigQuery SQL syntax reference: QUALIFY, PIVOT, MERGE, CTEs, partitioned and clustered tables, scripting and INFORMATION_SCHEMA. 31 statements and clauses with examples and cost notes.
- [The Bill Is Right: Guess Your BigQuery Bill | Masthead](https://mastheadata.com/bigquery/the-bill-is-right.md): A free game show for data teams. Guess the monthly BigQuery bill from real Google Cloud list prices: three tries, land within 15% to win.
- [BigQuery Timestamp Functions: Syntax, Time Zones and Examples | Masthead](https://mastheadata.com/bigquery/timestamp-functions.md): TIMESTAMP is an absolute point in time with microsecond precision, stored in UTC. 12 timestamp functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Hash and Utility Functions: FARM_FINGERPRINT, UUID, SHA256 | Masthead](https://mastheadata.com/bigquery/utility-functions.md): Hashing, unique IDs and a few utility functions that show up in pipelines: deterministic sampling, surrogate keys, deduplication and raising your own errors.. 6 hash and utility functions with syntax, runnable examples, common mistakes and cost notes.
- [BigQuery Window Functions: ROW_NUMBER, LAG, RANK and More | Masthead](https://mastheadata.com/bigquery/window-functions.md): Window (analytic) functions compute a value for every row from a window of related rows, defined with OVER (PARTITION BY ... 11 window functions with syntax, runnable examples, common mistakes and cost notes.
