Request a demo

BigQuery · String function

BigQuery REPLACE

REPLACE(value, from, to) replaces every occurrence of a substring: REPLACE(phone, ' ', '') removes all spaces. Matching is exact and case-sensitive; use REGEXP_REPLACE for patterns and TRANSLATE for single characters.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

REPLACE substitutes every non-overlapping occurrence of from_pattern with to_pattern, scanning left to right. Pass an empty string as to_pattern to remove text. The match is literal: no wildcards, no regular expressions, and no case folding, so REPLACE(status, 'paid', ...) doesn't touch Paid or PAID.

An empty from_pattern returns the value unchanged. A NULL in any argument returns NULL, including a NULL replacement.

To remove several different characters in one call, use TRANSLATE or REGEXP_REPLACE with a character class (r'[()\- ]') rather than nesting REPLACE calls. For case-insensitive replacement, use REGEXP_REPLACE with the (?i) flag.

Syntax

REPLACE(original_value, from_pattern, to_pattern)

Arguments and return value

ArgumentDescription
original_valueThe STRING or BYTES value to change.
from_patternThe literal text to find. If empty, nothing is replaced.
to_patternThe replacement text. Use '' to delete matches.

Returns: STRING or BYTES, the same type as original_value.

Examples

Remove and replace text

SELECT
  REPLACE('+1 (415) 555-0100', ' ', '') AS without_spaces,
  REPLACE('2026/11/23', '/', '-') AS iso_like_date,
  REPLACE('Paid paid PAID', 'paid', 'settled') AS case_sensitive;
Result
without_spacesiso_like_datecase_sensitive
+1(415)555-01002026-11-23Paid settled PAID

Non-overlapping matches, empty pattern and NULLs

SELECT
  REPLACE('banana', 'ana', 'X') AS non_overlapping,
  REPLACE('banana', '', 'X') AS empty_pattern,
  REPLACE('banana', 'a', CAST(NULL AS STRING)) AS null_replacement;
Result
non_overlappingempty_patternnull_replacement
bXnabananaNULL

Clean a currency string before casting

WITH invoices AS (
  SELECT 'INV-1' AS invoice_id, '$1,234.50' AS amount_text UNION ALL
  SELECT 'INV-2', '$980.00'
)
SELECT
  invoice_id,
  CAST(REPLACE(REPLACE(amount_text, '$', ''), ',', '') AS NUMERIC) AS amount
FROM invoices
ORDER BY invoice_id;
Result
invoice_idamount
INV-11234.5
INV-2980

Common mistakes

  • Expecting case-insensitive matching. REPLACE is case-sensitive. Use REGEXP_REPLACE(value, r'(?i)paid', 'settled').
  • Expecting wildcards. % and _ are literal characters in REPLACE. Use REGEXP_REPLACE for patterns.
  • Calling REPLACE with two arguments, as in Snowflake or Redshift, to delete text. BigQuery requires three; pass '' as the replacement.
  • Nesting many REPLACE calls to strip characters. TRANSLATE(phone, '()- ', '') or REGEXP_REPLACE(phone, r'[^0-9+]', '') is shorter and easier to maintain.

FAQ

How do I remove characters from a string in BigQuery?

For one substring, REPLACE(value, 'x', ''). For a set of characters, TRANSLATE(value, '()- ', ''). For everything except allowed characters, REGEXP_REPLACE(value, r'[^0-9]', '').

Is BigQuery REPLACE case-sensitive?

Yes. To replace regardless of case, use REGEXP_REPLACE(value, r'(?i)text', 'replacement').

What is the difference between REPLACE and REGEXP_REPLACE?

REPLACE matches literal text and is simpler and cheaper. REGEXP_REPLACE matches an RE2 regular expression and can reuse captured groups in the replacement with \1.

More string functions

All BigQuery string functions · All functions · BigQuery error messages

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.