Due to the complexity of your problem, the solution depends on the engine you are using. This is because to solve it you must use the look and look forward, and each engine is not the same.
My answer uses the Ruby mechanism. Validation is only one RegEx, but I have all the code here to better explain.
Please note that due to the Ruby RegEx mechanism (or my knowledge), optional forward / reverse lookups are not possible. So I need a little problem with spaces before and after the comma.
Here is my code:
orgTexts = [ '"asdf","asdf"', '"", "asdf"', '"asdf", ""', '"adsf", "", "asdf"', '"asdf""asdf", "asdf"', '"asdf", """asdf"""', '"asdf", """"' ] orgTexts.each{|orgText|
When executing the code, it prints:
"asdf","asdf" ------------- "asdf","asdf": false "","asdf" --------- "","asdf": false "asdf","" --------- "asdf","": false "adsf","","asdf" ---------------- "adsf","","asdf": false "asdf""asdf","asdf" -----^^------------ "asdf""asdf","asdf": true "asdf","""asdf""" --------^^----^^- "asdf","""asdf""": true "asdf","""" --------^^- "asdf","""": true
I hope I give you some ideas that you can use with another engine and language.