[MDEV-27043] REGEXP / REGEXP_REPLACE operations with empty source string match, but do not replace Created: 2021-11-14  Updated: 2021-11-14

Status: Open
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 10.4.12
Fix Version/s: None

Type: Bug Priority: Trivial
Reporter: Sybille Peters Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: regexp, regexp_replace
Environment:

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.


Generated at Thu Feb 08 09:49:54 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.