Details
-
Bug
-
Status: Open (View Workflow)
-
Trivial
-
Resolution: Unresolved
-
10.4.12
-
None
-
mysql console
Description
REGEXP_REPLACE does not replace a match with source string empty string (''), but REGEXP does match the empty string with a similar regex (.*). This seems inconsistent.
Examples:
Example 1. REGEP_REPLACE with empty source string: does not replace
SELECT REGEXP_REPLACE('', '^(.*)$', '\\1 hello'); |
result: '' |
Example 2. REGEXP with empty source string: does match
select '' REGEXP '^.*$'; |
result: 1
|
Example 3: compare with perl:
echo '' | perl -p -e "s/.*/hello/" |
Result: hello
|
I posted the question on Stack Overflow and was referred here.
I wasn't sure if this was really a bug, but it seems inconsistent - MariaDB uses https://mariadb.com/kb/en/pcre/, the perl command line as well as regex101 using perl do a replacement on the empty string.