#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^(?!(?:[^,()]*|(?:\([^)]*\)))*$).*$"
Local $sString = "foobar" & @CRLF & _
"foo,bar" & @CRLF & _
"foo(xx,yy)bar" & @CRLF & _
"foo(xx,yy),baz" & @CRLF & _
"foo,(xx,yy)qux" & @CRLF & _
"" & @CRLF & _
"a,b,c,d{" & @CRLF & _
" a,b(c, d),e { " & @CRLF & _
"a,(b,c),d{" & @CRLF & _
"a , bwefbfrew{" & @CRLF & _
"a,:is(b,c)s ss:is(b,c)sssss{" & @CRLF & _
"wefewfew,fewf{" & @CRLF & _
"fwafaewa,(b,c){" & @CRLF & _
"" & @CRLF & _
"wefwefewfee{" & @CRLF & _
"(a,b,c,d)eeeeee(few)eeee{" & @CRLF & _
"ewfeweew{" & @CRLF & _
"wafewaf(s)ewfewew(){" & @CRLF & _
"afewfe(s,)wfew{" & @CRLF & _
"fef ewee{" & @CRLF & _
"a sefe few:has(few,few){" & @CRLF & _
"aafew:has(few,fewf,few){" & @CRLF & _
"" & @CRLF & _
"span:is(p, b, a),da{" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
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