- 类别:
REGEXP_LIKE¶
执行比较以确定字符串是否与指定模式相匹配。两个输入都必须是文本表达式。
REGEXP_LIKE 与 [ NOT ] LIKE 函数类似,但使用 POSIX 扩展的正则表达式而不是 SQL LIKE 模式语法。它支持比 LIKE 更复杂的匹配条件。
小技巧
您可以使用搜索优化服务,提高用于调用此函数的查询的性能。有关详细信息,请参阅 搜索优化服务。
- 别名:
:doc:`rlike`(第 1 种语法)
语法¶
实参¶
必填:
subject用于搜索匹配项的字符串。
pattern要匹配的模式。
有关指定模式的准则,请参阅 字符串函数(正则表达式)。
可选:
parameters包含一个或多个字符的字符串,指定用于搜索匹配项的参数。支持的值:
参数
描述
c区分大小写的匹配
i不区分大小写的匹配
m多行模式
e提取子匹配项
sPOSIX 通配符
.与\n匹配默认:
c有关更多详细信息,请参阅 为正则表达式指定参数。
返回¶
Returns a BOOLEAN value or NULL:
Returns TRUE if there is a match.
Returns FALSE if there isn't a match.
如果任何实参为 NULL,则返回 NULL。
使用说明¶
该函数在两端隐式锚定一个模式(例如
''自动变为'^$',并且'ABC'自动变为'^ABC$')。要匹配任何以 ABC 开头的字符串,模式将是'ABC.*'。反斜杠字符 (
\) 是转义字符。有关更多信息,请参阅 在以单引号括起的字符串常量中指定正则表达式。有关更多使用说明,请参阅 一般使用说明,了解正则表达式函数。
排序规则详细信息¶
Arguments with collation specifications currently aren't supported.
示例¶
The following examples use the REGEXP_LIKE function:
有关正则表达式的其他示例,请参阅 [ NOT ] REGEXP。
Run basic regular expression queries on strings¶
创建一个包含城市名称的表:
You can use .* as a wildcard to match as many characters as possible. The following example matches the
pattern Fran anywhere in the string value:
The following example uses the i parameter for case-insensitive matching:
To find a pattern that matches the beginning of a string value, run a query that uses a wildcard:
使用通配符执行区分大小写的查询:
You can use the \w+ metacharacter to match one word and \s metacharacter to match one whitespace character, such
as a space or a tab. The following query searches for the values that include one word, followed by a whitespace
character, followed by one word:
The output for the query doesn't include San Luis Obispo because that value has three words with
a space between the first and second words instead of only two words with a space in between them.
In a regular expression, you can often use an uppercase metacharacter to negate the meaning of a lowercase metacharacter. For
example, run a query that searches for the values that don't include a whitespace character between two words by using the
\S metacharacter:
Run regular expression queries on strings with special characters¶
The examples in this section search for values with special characters, which are characters other than a-z, A-Z, underscore (“_”), or decimal digit.
反斜杠字符 (\) 是转义字符。有关更多信息,请参阅 在以单引号括起的字符串常量中指定正则表达式。
Create a table, and then insert some values with special characters:
The first inserted value doesn't contain special characters.
To show the data, query the table:
You can search for any special character by using the \W Perl backslash-sequence, which searches
for characters that aren't "word" characters. For example, the following query searches for the values
in the table that have special characters:
To search for metacharacters in a single-quoted string constant, you must
escape the metacharacter with two backslashes. For example, the following query searches for the values that
contain the $ metacharacter:
If you search for a backslash, an additional backslash escape character is required. For example, the following
query searches for the values that contain the \ or the . metacharacter: