I am trying to split a comma delimited string using the following code. The regex code for comma-delimited is used in one of my online courses. I am trying to understand the following regex with lookaround how it works but couldn't get it completely. Can someone let me know how it works?
I know ?: is for non-capturing group and ?= is for look ahead but not sure how it works in the current context.
import re
pattern = re.compile(r',(?=(?:[^"]*"[^"]*")*[^"]*$)')
text = 'tarcac,"this is, test1","this is, test2", 123566, testdata'
results= re.split(pattern, text)
for r in results:
print(r.strip())
Output is
tarcac
"this is, test1"
"this is, test2"
123566
testdata