the function you're looking for is called replace
:
from pyspark.sql import functions as F
sdf.withColumn("data - A", F.expr("replace(data, coalesce(A, ''), '')")).show(
truncate=False
)
+---------------------------------------------------+-----------------+----------------------------------+
|data |A |data - A |
+---------------------------------------------------+-----------------+----------------------------------+
|https://example1.org/path/to/file?param=42#fragment|param=42#fragment|https://example1.org/path/to/file?|
|https://example2.org/path/to/file |null |https://example2.org/path/to/file |
+---------------------------------------------------+-----------------+----------------------------------+
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…