I discovered that I can use an or in my expression to find anything in parenthesis OR any comma. With this method it won't select any individual commas that are inside the parenthesis groups. (Thanks to zx81 in this post.)
,|\((?:[^()]++|(?R))*\)
With that expression I can use the substitution |$0|
to surround each matching group with the |
character. Then it is easy to find the stand-alone commas with |,|
and replace with my carriage return pattern, then replace all remaining |
's with an empty string.
; AutoHotkey snippet below
s := RegExReplace( s, ",|\((?:[^()]++|(?R))*\)", "|$0|" )
s := StrReplace( s, "|,|" , ",`r`n" . A_Tab )
s := StrReplace( s, "|" , "")
Regex substitution example