I have a pyspark table like this.
|col |
|a function createdf and function roll |
|ground function power |
I am trying to capture the pattern function <word> and create a new column.
My expected output will be
|col | new_col
|a function createdf and function roll | [function createdf, function roll]
|ground function power | [function power]
Code I tried:
pat_function_definition = '((function)\s+(\w+))'
df.withColumn('temp', f.split(f.regexp_replace("col", "(((function)\s+(\w+)))" , "$1"), ",")).show()
Spark version is 2.4.