メインコンテンツまでスキップ

正規表現の数

文字列str内で Java 正規表現パターンregexpが一致する回数を返します。

対応する Databricks SQL 関数については、 regexp_count関数を参照してください。

構文

Python
from pyspark.databricks.sql import functions as dbf

dbf.regexp_count(str=<str>, regexp=<regexp>)

パラメーター

パラメーター

Type

説明

str

pyspark.sql.Column または str

取り組むターゲットカラム。

regexp

pyspark.sql.Column または str

適用する正規表現パターン。

Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([("1a 2b 14m", r"\d+")], ["str", "regexp"])
df.select('*', dbf.regexp_count('str', dbf.lit(r'\d+'))).show()
df.select('*', dbf.regexp_count('str', dbf.lit(r'mmm'))).show()
df.select('*', dbf.regexp_count("str", dbf.col("regexp"))).show()
df.select('*', dbf.regexp_count(dbf.col('str'), "regexp")).show()