regexp_substr 函数

适用于:check marked yes Databricks SQL check marked yes Databricks Runtime 11.2 及更高版本

返回 str 中与 regexp 匹配的第一个 substring。

语法

regexp_substr( str, regexp )

参数

  • str:要匹配的 STRING 表达式。
  • regexp:具有模式的 STRING 表达式。

返回

一个 STRING

字符串 regexp 必须是 Java 正则表达式。 字符串字面量未转义。 例如,若要与 '\abc' 匹配,regexp 的正则表达式可以是 '^\\abc$'

如果 regexp 格式不正确,则函数将返回 INVALID_PARAMETER_VALUE 错误。

如果任一参数为 NULL 或找不到模式,则结果为 NULL

示例

> SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
 Steven

> SELECT regexp_substr('Mary had a little lamb', 'Ste(v|ph)en');
 NULL

> SELECT regexp_substr(NULL, 'Ste(v|ph)en');
 NULL

> SELECT regexp_substr('Mary had a little lamb', NULL);
 NULL