input = "'Siva', ['Aswin','latha'], 'Senthil',['Aswin','latha']"
expected output:
"'Siva', [Aswin,latha], 'Senthil',[Aswin,latha]"
I have used positive lookbehind and lookahead but its not working.
pattern
(?<=\[)\'+(?=\])
You can use re.findall with an alternation pattern to find either fragments between ] and [, or otherwise non-single-quote characters, and then join the fragments together with ''.join:
''.join(re.findall(r"[^\]]*\[|\][^\[]*|[^']+", input))
Demo: https://replit.com/@blhsing/ClassicFrostyBookmark
This is generally more efficient than using re.sub with a callback since there is overhead involved in making a callback for each match.
[']or contain multiple'"'Siva', ['Aswin','latha'], 'Senthil',['[Aswin','[latha]']"?