pyspark.sql.functions.regexp_replace

pyspark.sql.functions.regexp_replace(str, pattern, replacement)[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='-----')]