Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-27043

REGEXP / REGEXP_REPLACE operations with empty source string match, but do not replace

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Trivial
    • Resolution: Unresolved
    • 10.4.12
    • None
    • Parser
    • 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sypets Sybille Peters
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.