How to Use Regex in BigQuery

Last updated July 26, 2026 · By the SaturnSQL team

REGEXP_CONTAINS tests whether a string matches a pattern, REGEXP_EXTRACT pulls out the first matching group, and REGEXP_REPLACE substitutes matches with new text.

SELECT REGEXP_CONTAINS(email, r'^[\w.+-]+@[\w-]+\.[a-z]{2,}$') AS is_valid_email
FROM users;

Extracting a capture group

SELECT url, REGEXP_EXTRACT(url, r'/blog/([a-z0-9-]+)') AS slug
FROM events;

Replacing matches

SELECT REGEXP_REPLACE(phone, r'[^0-9]', '') AS digits_only
FROM users;

Use a raw string literal (prefixed with r) for regex patterns so backslashes do not need double escaping.

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Related BigQuery guides