Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
29c9cc75
提交
29c9cc75
authored
8月 05, 2016
作者:
Noel Grandin
提交者:
GitHub
8月 05, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #323 from Akkuzin/regexp_match_enhance
Regular expression functions (REGEXP_REPLACE, REGEXP_LIKE) enhancement
上级
1ae4f80c
29d286cc
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
116 行增加
和
6 行删除
+116
-6
help.csv
h2/src/docsrc/help/help.csv
+40
-2
Function.java
h2/src/main/org/h2/expression/Function.java
+55
-2
help.csv
h2/src/main/org/h2/res/help.csv
+5
-1
testScript.sql
h2/src/test/org/h2/test/testScript.sql
+14
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+2
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
29c9cc75
...
...
@@ -3255,15 +3255,53 @@ TRIM(BOTH '_' FROM NAME)
"
"Functions (String)","REGEXP_REPLACE","
REGEXP_REPLACE(inputString, regexString, replacementString)
REGEXP_REPLACE(inputString, regexString, replacementString
[, flagsString]
)
","
Replaces each substring that matches a regular expression.
For details, see the Java ""String.replaceAll()"" method.
If any parameter is null, the result is null.
If any parameter is null (except optional flagsString parameter), the result is null.
Flags values limited to 'i', 'c', 'n', 'm'. Other symbols causes exception.
Multiple symbols could be uses in one flagsString parameter (like 'im').
Later flags overrides first ones, for example 'ic' equivalent to case sensitive matching 'c'.
'i' enables case insensitive matching (Pattern.CASE_INSENSITIVE)
'c' disables case insensitive matching (Pattern.CASE_INSENSITIVE)
'n' allows the period to match the newline character (Pattern.DOTALL)
'm' enables multiline mode (Pattern.MULTILINE)
","
REGEXP_REPLACE('Hello World', ' +', ' ')
REGEXP_REPLACE('Hello WWWWorld', 'w+', 'W', 'i')
"
"Functions (String)","REGEXP_LIKE","
REGEXP_LIKE(inputString, regexString [, flagsString])
","
Matches string to a regular expression.
For details, see the Java ""Matcher.find()"" method.
If any parameter is null (except optional flagsString parameter), the result is null.
Flags values limited to 'i', 'c', 'n', 'm'. Other symbols causes exception.
Multiple symbols could be uses in one flagsString parameter (like 'im').
Later flags overrides first ones, for example 'ic' equivalent to case sensitive matching 'c'.
'i' enables case insensitive matching (Pattern.CASE_INSENSITIVE)
'c' disables case insensitive matching (Pattern.CASE_INSENSITIVE)
'n' allows the period to match the newline character (Pattern.DOTALL)
'm' enables multiline mode (Pattern.MULTILINE)
","
REGEXP_LIKE('Hello World', '[A-Z ]*', 'i')
"
"Functions (String)","REPEAT","
REPEAT(string, int)
","
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
29c9cc75
...
...
@@ -20,6 +20,7 @@ import java.util.Calendar;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
java.util.regex.Pattern
;
import
java.util.regex.PatternSyntaxException
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Command
;
...
...
@@ -120,6 +121,8 @@ public class Function extends Expression implements FunctionCall {
FILE_READ
=
225
,
TRANSACTION_ID
=
226
,
TRUNCATE_VALUE
=
227
,
NVL2
=
228
,
DECODE
=
229
,
ARRAY_CONTAINS
=
230
,
FILE_WRITE
=
232
;
public
static
final
int
REGEXP_LIKE
=
240
;
/**
* Used in MySQL-style INSERT ... ON DUPLICATE KEY UPDATE ... VALUES
*/
...
...
@@ -295,12 +298,13 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"XMLCDATA"
,
XMLCDATA
,
1
,
Value
.
STRING
);
addFunction
(
"XMLSTARTDOC"
,
XMLSTARTDOC
,
0
,
Value
.
STRING
);
addFunction
(
"XMLTEXT"
,
XMLTEXT
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"REGEXP_REPLACE"
,
REGEXP_REPLACE
,
3
,
Value
.
STRING
);
addFunction
(
"REGEXP_REPLACE"
,
REGEXP_REPLACE
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"RPAD"
,
RPAD
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"LPAD"
,
LPAD
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"TO_CHAR"
,
TO_CHAR
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"ORA_HASH"
,
ORA_HASH
,
VAR_ARGS
,
Value
.
INT
);
addFunction
(
"TRANSLATE"
,
TRANSLATE
,
3
,
Value
.
STRING
);
addFunction
(
"REGEXP_LIKE"
,
REGEXP_LIKE
,
VAR_ARGS
,
Value
.
BOOLEAN
);
// date
addFunctionNotDeterministic
(
"CURRENT_DATE"
,
CURRENT_DATE
,
...
...
@@ -1381,9 +1385,13 @@ public class Function extends Expression implements FunctionCall {
case
REGEXP_REPLACE:
{
String
regexp
=
v1
.
getString
();
String
replacement
=
v2
.
getString
();
String
regexpMode
=
v3
==
null
||
v3
.
getString
()
==
null
?
""
:
v2
.
getString
();
int
flags
=
makeRegexpFlags
(
regexpMode
);
try
{
result
=
ValueString
.
get
(
v0
.
getString
().
replaceAll
(
regexp
,
replacement
),
Pattern
.
compile
(
regexp
,
flags
).
matcher
(
v0
.
getString
())
.
replaceAll
(
replacement
),
database
.
getMode
().
treatEmptyStringsAsNull
);
}
catch
(
StringIndexOutOfBoundsException
e
)
{
throw
DbException
.
get
(
...
...
@@ -1655,6 +1663,19 @@ public class Function extends Expression implements FunctionCall {
database
.
getMode
().
treatEmptyStringsAsNull
);
}
break
;
case
REGEXP_LIKE:
{
String
regexp
=
v1
.
getString
();
String
regexpMode
=
v2
==
null
||
v2
.
getString
()
==
null
?
""
:
v2
.
getString
();
int
flags
=
makeRegexpFlags
(
regexpMode
);
try
{
result
=
ValueBoolean
.
get
(
Pattern
.
compile
(
regexp
,
flags
)
.
matcher
(
v0
.
getString
()).
find
());
}
catch
(
PatternSyntaxException
e
)
{
throw
DbException
.
get
(
ErrorCode
.
LIKE_ESCAPE_ERROR_1
,
e
,
regexp
);
}
break
;
}
case
VALUES:
result
=
session
.
getVariable
(
args
[
0
].
getSchemaName
()
+
"."
+
args
[
0
].
getTableName
()
+
"."
+
args
[
0
].
getColumnName
());
...
...
@@ -2110,6 +2131,30 @@ public class Function extends Expression implements FunctionCall {
return
hc
;
}
public
int
makeRegexpFlags
(
String
stringFlags
)
{
int
flags
=
Pattern
.
UNICODE_CASE
;
if
(
stringFlags
!=
null
)
{
for
(
int
i
=
0
;
i
<
stringFlags
.
length
();
++
i
)
{
switch
(
stringFlags
.
charAt
(
i
))
{
case
'i'
:
flags
|=
Pattern
.
CASE_INSENSITIVE
;
break
;
case
'c'
:
flags
&=
~
Pattern
.
CASE_INSENSITIVE
;
break
;
case
'n'
:
flags
|=
Pattern
.
DOTALL
;
break
;
case
'm'
:
flags
|=
Pattern
.
MULTILINE
;
break
;
default
:
throw
DbException
.
get
(
ErrorCode
.
INVALID_VALUE_2
,
stringFlags
);
}
}
}
return
flags
;
}
@Override
public
int
getType
()
{
...
...
@@ -2199,6 +2244,14 @@ public class Function extends Expression implements FunctionCall {
case
CASE:
min
=
3
;
break
;
case
REGEXP_REPLACE:
min
=
3
;
max
=
4
;
break
;
case
REGEXP_LIKE:
min
=
2
;
max
=
3
;
break
;
default
:
DbException
.
throwInternalError
(
"type="
+
info
.
type
);
}
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
29c9cc75
...
...
@@ -1140,9 +1140,13 @@ TRIM ( [ { LEADING | TRAILING | BOTH } [ string ] FROM ] string )
","
Removes all leading spaces, trailing spaces, or spaces at both ends, from a string."
"Functions (String)","REGEXP_REPLACE","
REGEXP_REPLACE(inputString, regexString, replacementString)
REGEXP_REPLACE(inputString, regexString, replacementString
[, flagsString]
)
","
Replaces each substring that matches a regular expression."
"Functions (String)","REGEXP_LIKE","
REGEXP_LIKE(inputString, regexString [, flagsString])
","
Matches string to a regular expression."
"Functions (String)","REPEAT","
REPEAT(string, int)
","
...
...
h2/src/test/org/h2/test/testScript.sql
浏览文件 @
29c9cc75
...
...
@@ -167,6 +167,9 @@ drop table test;
call
regexp_replace
(
'x'
,
'x'
,
'
\'
);
> exception
call select 1 from dual where regexp_like('
x
', '
x
', '
\
');
> exception
select * from dual where x = x + 1 or x in(2, 0);
> X
> -
...
...
@@ -2112,6 +2115,17 @@ CALL REGEXP_REPLACE('abckaboooom', 'o+', 'o');
> abckabom
> rows: 1
select x from dual where REGEXP_LIKE('
aBc
', '
[
a
-
z
]
*
', '
i
');
> X
> -
> 1
> rows: 1
select x from dual where REGEXP_LIKE('
aBc
', '
[
a
-
z
]
*
', '
c
');
> X
> -
> rows: 0
SELECT '
Hello
' ~ '
He
.
*
' T1, '
HELLO
' ~ '
He
.
*
' F2, CAST('
HELLO
' AS VARCHAR_IGNORECASE) ~ '
He
.
*
' T3;
> T1 F2 T3
> ---- ----- ----
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
29c9cc75
...
...
@@ -720,4 +720,5 @@ xtime xts xvi xyz yacute year years yen yes yet yield yielding yjp ymd york you
young younger youngest your yourself youtube ytd yuml yyfxyy yyyymmdd zeile zen
zepfred zero zeroes zeros zeta zhang zip ziv zloty zone zones zurich zwj zwnj
recompiled incl reveal designators templates invoked candidate handshake altered
accomplished permanent clarify weaken excl alternatively dita imjcc optimizes
\ No newline at end of file
accomplished permanent clarify weaken excl alternatively dita imjcc optimizes
dotall multiline
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论