#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)\((?:[^()]++|(?R))*\)|,"
Local $sString = "SELECT Name AS [Object Name], Switch([Type]=5,'Query',[Type]=-32768,'Form',[Type]=6,'Table') AS [Object Type], Switch([Type]=5,1,[Type]=-32768,2,[Type] In (1,4,6),6) AS [Object Type ID], Left(Name,4) as Prefix, LTrim(RTrim(Mid([Name],5,30))) as Suffix" & @CRLF & _
"" & @CRLF & _
"SELECT "Amy's code is righteous.", left("abc",1), right('source code',4), "Bill's code has been righteous too."" & @CRLF & _
"" & @CRLF & _
"----------" & @CRLF & _
"" & @CRLF & _
"End goal is to replace all commas in SQL SELECT clause with comma+linefeed but ignore commas inside parenthesis (which may be nested)." & @CRLF & _
"" & @CRLF & _
"\((?:[^()]++|(?R))*\)" & @CRLF & _
"" & @CRLF & _
"This expression will find all of the nested parentheis using recursion. I want to do one of these two options:" & @CRLF & _
" a) Replace all commas in the matched groups with the pipe "|" character, " & @CRLF & _
" then with two simple StrReplace() calls: replace all commas with comma+linefeed, then replace all | with comma." & @CRLF & _
"OR" & @CRLF & _
" b) Select all text that is not in the matched group and replace commas with comma+linefeed." & @CRLF & _
"" & @CRLF & _
"I'm using AutoHotkey and the RegExReplace() function."
Local $sSubst = "|$0|"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm