Replaces all substrings that match the regular expression with a replacement string. Supports backreferences.
STRINGDiperbarui: 13 Jun 2026REGEXP_REPLACE(value, regexp, replacement)The source string
Regular expression pattern
Replacement string (supports \1, \2 backreferences)
1 SELECT 2 phone, 3 REGEXP_REPLACE(phone, r'[^0-9]', '') as clean_phone 4 FROM `project.dataset.contacts`;
Remove all non-numeric characters.
| phone | clean_phone |
|---|---|
| +62-812-345-678 | 62812345678 |
| (021) 123 4567 | 0211234567 |
1 SELECT 2 REGEXP_REPLACE('20240115', r'(\d{4})(\d{2})(\d{2})', r'\1-\2-\3') as formatted;
Format a date string using capturing groups.
1 SELECT 2 email, 3 REGEXP_REPLACE(email, r'(.).*@', r'\1***@') as masked 4 FROM `project.dataset.users`;
Mask the username portion of an email address.
| masked | |
|---|---|
| john@gmail.com | j***@gmail.com |
Sudah paham REGEXP_REPLACE? Latih langsung di browser
Latihan interaktif, langsung di browser.