'Pyspark Column split with pipe, but don't split when precedes escape character

I have dataframe with a column data like below image I want to split the column with pipe, but when pipe precedes with an escape character, ignore the pipe. ex:

  1. a|b1\|b2|c needs to convert as [a, b1\|b2, c]
  2. a|b|c needs to convert as [a, b, c]

I am able to split a string using below command, but unable to use this to split entire column, please help.

print(re.findall(r"(?:\[\|]|[^|\n])+", "a|b1|b2|c"))

Please help. Thank you enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source