答案1
你可以分两次完成。首先,替换不带引号的逗号:
/(?!\B"[^"]*),(?![^"]*"\B)/\|/gm
Input Output
--------------------------------- ---------------------------------
aaa,bbb,ccc,"ddd,eee","fff,ggg" aaa|bbb|ccc|"ddd,eee"|"fff,ggg"
"aaa,bbb",ccc,ddd,"eee,fff" "aaa,bbb"|ccc|ddd|"eee,fff"
"aaa,bbb","ccc,ddd","eee,fff",ggg "aaa,bbb"|"ccc,ddd"|"eee,fff"|ggg
然后只需将“ 替换为空即可获得所需的最终结果:
/"//gm
Input Output
--------------------------------- ---------------------------------
aaa|bbb|ccc|"ddd,eee"|"fff,ggg" aaa|bbb|ccc|ddd,eee|fff,ggg
"aaa,bbb"|ccc|ddd|"eee,fff" aaa,bbb|ccc|ddd|eee,fff
"aaa,bbb"|"ccc,ddd"|"eee,fff"|ggg aaa,bbb|ccc,ddd|eee,fff|ggg