pyspark.sql.functions.regexp_replace

pyspark.sql.functions.regexp_replace(str: ColumnOrName, pattern: str, replacement: str) → pyspark.sql.column.Column[source]

Replace all substrings of the specified string value that match regexp with rep.

New in version 1.5.0.

Examples

>>> df = spark.createDataFrame([('100-200',)], ['str'])
>>> df.select(regexp_replace('str', r'(\d+)', '--').alias('d')).collect()
[Row(d='-----')]