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

正規表現サブストリング

文字列str内の Java 正規表現regexpに一致する最初の部分文字列を返します。正規表現が見つからない場合、結果は null になります。

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

構文

Python
from pyspark.databricks.sql import functions as dbf

dbf.regexp_substr(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"])
Python
df.select('*', dbf.regexp_substr('str', dbf.lit(r'\d+'))).show()
df.select('*', dbf.regexp_substr('str', dbf.lit(r'mmm'))).show()
df.select('*', dbf.regexp_substr("str", dbf.col("regexp"))).show()
df.select('*', dbf.regexp_substr(dbf.col("str"), "regexp")).show()