A function to replace substrings based on regex patterns.
PostgreSQL function that replaces text matching a regex pattern with replacement text. Supports backreferences ($1, $2) to insert captured groups. Essential for complex text transformations that exceed LIKE capabilities.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 8.0 | REGEXP_REPLACE() added in MySQL 8.0. |
| PostgreSQL | ✓ Supported | 9.1 | |
| SQL Server | ✗ Not Supported | — | SQL Server does not support REGEXP_REPLACE. |
| Oracle | ✓ Supported | 12c | |
| SQLite | ✗ Not Supported | — | SQLite does not support REGEXP_REPLACE. |
This function is useful for text manipulation and data cleaning. However, support for it varies widely across SQL databases, with some lacking native regex replacement capabilities. Perhaps the ones that don't support it have played the 'I used regex to solve my problem; now I have two problems' game and rightly decided against supporting it.
REGEXP_REPLACE() added in MySQL 8.0.