适用于:
Databricks SQL
Databricks Runtime 11.3 LTS 及更高版本
返回 str 与 regexp 模式匹配的次数。
语法
regexp_count( str, regexp )
参数
str:要匹配的STRING表达式。regexp:具有模式的STRING表达式。
返回
INTEGER。
字符串 regexp 必须是 Java 正则表达式。
字符串字面量未转义。 例如,若要与 '\abc' 匹配,regexp 的正则表达式可以是 '^\\abc$'。
如果 regexp 格式不正确,则函数将返回 INVALID_PARAMETER_VALUE 错误。
如果任一参数为 NULL,则结果为 NULL。
示例
> SELECT regexp_count('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
2
> SELECT regexp_count('Mary had a little lamb', 'Ste(v|ph)en');
0
> SELECT regexp_count(NULL, 'Ste(v|ph)en');
NULL
> SELECT regexp_instr('Mary had a little lamb', NULL);
NULL