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