What is the best way to apply the following transformation to a column in a dataframe in Spark 2.40 Scala. I was attempting udf or regex replace but could not achieve the desired outcome.
column_1 in the below example is a string.
Data frame Input:
column_1
#;#;Runner#;#;bob
#;#;#;
Desired Result
column_1
null#;null#;Runner#;null#;bob
null#;null#;null
Solution:
Following the suggestions below. This was how I resolved the issue. In this case I replaced with commas first then later replaced the comma delimiter with #;
select_df
.withColumn("column_1", regexp_replace(col("column_1"), "(?<![a-zAZ0-9]),", "null,"))
.withColumn("column_1", regexp_replace(col("column_1"), ",]$", ",null"))
.withColumn("column_1", regexp_replace(col("column_1"), ",", "#;"))