I need to split string based on ,
except when inside |
I tried the approach given Splitting on comma outside quotes but doesn't work.
This is where I want to add regex
dfs = [pd.DataFrame(allViolations[c].astype(str).str.split(regex).tolist())
.rename(lambda x: 'Field{}'.format(x + 1),axis=1)
for c in allViolations.columns]
Here I want to replace regex so can't use re
. Is there any other way or if I could simplify above statement to use re
test = 'a,b'
test1 = '|a,b|'
regex = ",(?=(?:[^|]*|[^|]*|)*[^|]*$)"
r = test.split(regex)
print(r) //['a,b']
r1= test1.split(regex)
print(r1) //['|a,b|']