重庆思庄Oracle、Redhat认证学习论坛

标题: Oracle的正则表达式总结 [打印本页]

作者: 5dm    时间: 2012-11-5 10:25
标题: Oracle的正则表达式总结
 

Symbol

Description

*

Matches zero or more occurrences

|

Alteration operator for specifying alternative matches

 ^/$

Matches the start-of-line/end-of-line

[ ]

Bracket expression for a matching list matching any one of the expressions represented in the list

{m}

Matches exactly m times

{m,n}

Matches at least m times but no more than n times

[: :]

Specifies a character class and matches any character in that class

\

Can have 4 different meanings: 1. Stand for itself. 2. Quote the next character. 3. Introduce an operator. 4. Do nothing.

+

Matches one or more occurrences

?

Matches zero or one occurrence

.

Matches any character in the supported character set, except NULL

()

Grouping expression, treated as a single subexpression

[==]

Specifies equivalence classes

\n

Back-reference expression

[..]

Specifies one collation element, such as a multicharacter element


Function Name

Description

REGEXP_LIKE

Similar to the LIKE operator, but performs regular expression matching instead of simple pattern matching

REGEXP_REPLACE

Searches for a regular expression pattern and replaces it with a replacement string

REGEXP_INSTR

Searches for a given string for a regular expression pattern and returns the position where the match is found

REGEXP_SUBSTR

Searches for a regular expression pattern within a given string and returns the matched substring


作者: 5dm    时间: 2012-11-6 09:58

中文助消化

 

 

Oracle正则表达式(regularexpression)

元字符
 字符含义
 举例说明
 
^
 匹配字符串的开始位置(在[]中使用,此时它表示不接受该字符集合。
 ^a:匹配以a开始的字符串

[^a]:匹配不含a的字符串
 
-
 当使用在a-m表示范围;

当使用在第一个字符时表示

连字符串,如[-abc]
 
 
$
 匹配字符结束位置
 ‘a$':匹配以a结束的字符串
 
.
 匹配除换行符 n之外的任何单字符。
 
 
?
 匹配前面的子表达式零次或一次
 tr(y(ing)?):可以表示try或者trying
 
*
 匹配前面的子表达式零次或多次
 
 
+
 匹配前面的子表达式一次或多次
 
 
()
 标记一个子表达式的开始和结束位置
 a(b)*可以匹配

ab,abb,abbb,youabb

(c|d)匹配c或d
 
[]
 标记一个中括号表达式
 [cd]匹配选择c或d等同于

(c|d)。匹配的是单字符,[^cd]是匹配c,d之外的单字符。

[a-z]表示所有小写字母
 
{m,n}
 m= <出现次数 <=n,'{m}'表示出现m次,'{m,}'表示至少出现m次。
 
 
|
 表示或者的关系。指明两项之间的一个选择
 
 
字符簇
 字符含义
 
 
[[:alpha:]]
 任何字母。
 
 
[[:digit:]]
 [[:digit:]] 任何数字。
 
 
[[:alnum:]]
 任何字母和数
 
 
[[:space:]]
 任何白字符。
 
 
[[:upper:]]
 任何大写字母。
 
 
[[:lower:]]
 任何小写字母。
 
 
[[:punct:]]
 任何标点符号。
 
 
[[:xdigit:]]
 任何16进制的数字,相当于[0-9a-fA-F]。
 
 

Oracle支持正则表达式的内置函数

名称
 语法
 备注
 
REGEXP_LIKE
 REGEXP_LIKE

(source_string,

pattern

[, match_parameter]

)
 source_string:

源字符串

Pattern:

正则表达式

match_parameter:

匹配模式(i:不区分大小写;c:区分大小写;n:允许使用可以匹配任意字符串的操作符;m:将x作为一个包含多行的字符串。
 
REGEXP_REPLACE
 REGEXP_REPLACE

(source_string,

pattern

[,replace_string]

[,position]

[,occurtence]

[,match_parameter]

)
 replace_string:

用于替换的字符串

Position:

开始搜索的起始位置

occurtence

指定替换第n次出现字符串

其他同上。
 
REGEXP_SUBSTR
 REGEXP_SUBSTR

(source_string, pattern

[,position

[,occurrence

[,match_parameter]]]

)
 Position:

指定在字符串中准确位置,默认为1

Occurrence:

指定在源字符串匹配过程中相对其他字符串,哪个字符串应该匹配。例如

select regexp_substr('The zip code

80831 is for falcon, co',

'[[:alpha:]]{3,}', 1, 3)

from dual;

结果选择的是code而非The或zip。
 
REGEXP_INSTR
 REGEXP_INSTR

(source_string,

pattern

[,start_position

[,occurrence

[,return_option

[,match_parameter]]]]

)
 start_position:

开始搜索位置

Occurrence:

第n次出现pattern,默认为1

return_option:

0:pattern的起始位置

1:pattern下一个字符起始位置

默认为0
 
REGEXP_COUNT
 REGEXP_COUNT

(source_string,

pattern

[[,start_position]

[,match_parameter]])

 






欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2