正規表現の置換
正規表現に一致する指定された文字列値のすべての部分文字列を置換します。
対応する Databricks SQL 関数については、 regexp_replace関数を参照してください。
構文
Python
from pyspark.databricks.sql import functions as dbf
dbf.regexp_replace(string=<string>, pattern=<pattern>, replacement=<replacement>)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
|
| 列名または文字列値を含む列 |
|
| 正規表現パターンを含む列オブジェクトまたは文字列 |
|
| 置換を含む列オブジェクトまたは文字列 |
例
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame(
[("100-200", r"(\d+)", "--")],
["str", "pattern", "replacement"]
)
df.select('*', dbf.regexp_replace('str', r'(\d+)', '--')).show()
Python
df.select('*',
dbf.regexp_replace(dbf.col("str"), dbf.col("pattern"), dbf.col("replacement"))
).show()