Extracts the first substring that matches the regular expression. If the pattern has a capturing group, returns that group instead.
STRINGDiperbarui: 13 Jun 2026REGEXP_EXTRACT(value, regexp [, position [, occurrence]])The source string
Regular expression with an optional capturing group
Starting position for the search (1-based)
Default: 1
The nth occurrence to extract
Default: 1
1 SELECT 2 email, 3 REGEXP_EXTRACT(email, r'@([a-zA-Z0-9.-]+)') as domain 4 FROM `project.dataset.users`;
Extract the domain from an email address using a capturing group.
| domain | |
|---|---|
| john@gmail.com | gmail.com |
| jane@company.co.id | company.co.id |
1 SELECT 2 text, 3 REGEXP_EXTRACT(text, r'[0-9]+') as first_number 4 FROM `project.dataset.logs`;
Extract the first number from a text string.
| text | first_number |
|---|---|
| Order #12345 confirmed | 12345 |
| Invoice 2024-001 | 2024 |
1 SELECT 2 REGEXP_EXTRACT('abc123def456', r'[0-9]+', 1, 2) as second_number;
Extract the second occurrence of the pattern.
Sudah paham REGEXP_EXTRACT? Latih langsung di browser
Latihan interaktif, langsung di browser.
REGEXP_INSTR