次の方法で共有


regexp_count 関数

適用対象:check marked yes Databricks SQL Databricks Runtime 11.3 LTS 以降

strregexp パターンと一致する回数を返します。

構文

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