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