提交 18b43461 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix \$ handling in REGEXP_REPLACE() in Oracle mode and optimize implementation

上级 d96d5111
......@@ -1419,22 +1419,11 @@ public class Function extends Expression implements FunctionCall {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < replacement.length(); i++) {
char c = replacement.charAt(i);
switch (c) {
case '$':
if (c == '$') {
sb.append('\\');
break;
case '\\':
if (i + 1 < replacement.length()) {
c = replacement.charAt(i + 1);
if (c >= '0' && c <= '9') {
sb.append('$');
continue;
}
if (c == '\\') {
sb.append('\\');
i++;
}
}
} else if (c == '\\' && ++i < replacement.length()) {
c = replacement.charAt(i);
sb.append(c >= '0' && c <= '9' ? '$' : '\\');
}
sb.append(c);
}
......
......@@ -32,6 +32,12 @@ select regexp_replace('first last', '(\w+) (\w+)', '\\2 \1') as X from dual;
> \2 first
> rows: 1
select regexp_replace('first last', '(\w+) (\w+)', '\$2 \1') as X from dual;
> X
> --------
> $2 first
> rows: 1
select regexp_replace('first last', '(\w+) (\w+)', '$2 $1') as X from dual;
> X
> -----
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论