1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-6965 non-captured group \2 in regexp_replace

This commit is contained in:
Alexander Barkov
2014-11-10 16:43:27 +04:00
parent 080fdbf937
commit 9e8202013a
3 changed files with 19 additions and 5 deletions

View File

@ -839,3 +839,9 @@ SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2');
SELECT REGEXP_SUBSTR('abc','.+'); SELECT REGEXP_SUBSTR('abc','.+');
REGEXP_SUBSTR('abc','.+') REGEXP_SUBSTR('abc','.+')
a a
SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2');
REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2')
/abc
SET default_regex_flags=DEFAULT;
#
# MDEV-6965 non-captured group \2 in regexp_replace

View File

@ -397,3 +397,8 @@ SET default_regex_flags='UNGREEDY';
SELECT REGEXP_SUBSTR('abc','.+'); SELECT REGEXP_SUBSTR('abc','.+');
SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2'); SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2');
SET default_regex_flags=DEFAULT; SET default_regex_flags=DEFAULT;
--echo #
--echo # MDEV-6965 non-captured group \2 in regexp_replace
--echo #
SELECT REGEXP_REPLACE('1 foo and bar', '(\\d+) foo and (\\d+ )?bar', '\\1 this and \\2that');

View File

@ -1379,12 +1379,15 @@ bool Item_func_regexp_replace::append_replacement(String *str,
break; /* End of line */ break; /* End of line */
beg+= cnv; beg+= cnv;
if ((n= ((int) wc) - '0') >= 0 && n <= 9 && n < re.nsubpatterns()) if ((n= ((int) wc) - '0') >= 0 && n <= 9)
{ {
/* A valid sub-pattern reference found */ if (n < re.nsubpatterns())
int pbeg= re.subpattern_start(n), plength= re.subpattern_end(n) - pbeg; {
if (str->append(source->str + pbeg, plength, cs)) /* A valid sub-pattern reference found */
return true; int pbeg= re.subpattern_start(n), plength= re.subpattern_end(n) - pbeg;
if (str->append(source->str + pbeg, plength, cs))
return true;
}
} }
else else
{ {