Bug #113153 Documentation on how to use captured groups in REGEXP_REPLACE
Submitted: 20 Nov 2023 20:46 Modified: 21 Nov 2023 6:46
Reporter: Nuno P Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[20 Nov 2023 20:46] Nuno P
Description:
Following a recent migration from MariaDB to MySQL, I was wondering why my "REGEXP_REPLACE" expressions were not correctly replacing when using captured groups.

Apparently, while MariaDB uses "\\1" format, MySQL uses "$1".

I was trying to see what the documentation says, but seems that there are no examples at all on how to use groups, in the page:

https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace

How to repeat:
MariaDB:

REGEXP_REPLACE(column, '.*(xx).*', '\\1')

MySQL:

REGEXP_REPLACE(column, '.*(xx).*', '$1')

Suggested fix:
My suggestion is that the documentation is improved to give at least one example on how to use captured groups in REGEXP_REPLACE.

Example for MariaDB:
https://mariadb.com/kb/en/regexp_replace/
[21 Nov 2023 6:46] MySQL Verification Team
Hello Nuno P,

Thank you for the document enhancement request.

regards,
Umesh
[6 Dec 2023 19:02] David Allen
Absolutely. I just ran into this and couldn't find the $1 documented anywhere; in the end, I had to talk with another SQL architect who just "knew" the answer.