regexp_replace
Replace all substrings of the specified string value that match regexp with replacement.
For the corresponding Databricks SQL function, see regexp_replace function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.regexp_replace(string=<string>, pattern=<pattern>, replacement=<replacement>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| column name or column containing the string value |
|
| column object or str containing the regexp pattern |
|
| column object or str containing the replacement |
Examples
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()