#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mx)^(?: # non-capture group (repeat)" & @CRLF & _
" (?| # branch reset for group 1" & @CRLF & _
" ([^)(><\n])| # either non-bracket... or:" & @CRLF & _
" <(?=.*(>))| # if < open angle capture > to group 1" & @CRLF & _
" >(?=.*(<))| # if > capture opening < to group 1" & @CRLF & _
" \((?=.*(\)))| # same for (), if ( capture ) to group 1" & @CRLF & _
" \)(?=.*(\()) # if ) catpure ( to group 1" & @CRLF & _
" )(?=.*((?(2)\1\2|\1))$) # cond (2): if not outer chr (fwd ref)" & @CRLF & _
")*? # as few as possible (lazy) / eof non-cap" & @CRLF & _
"[^)(><\n]? # the middle character (no parens)" & @CRLF & _
"\2$ # the right part (group 2 capture)"
Local $sString = "(_)tar<>rat(_)" & @CRLF & _
")()_<(*&bab&*)>_()(" & @CRLF & _
")(*?*)(" & @CRLF & _
"()<_<oxxo>_>()" & @CRLF & _
"<__>w(owiwo)w<__>" & @CRLF & _
"a(t<()((<oyo>))()>t)a" & @CRLF & _
"" & @CRLF & _
"v" & @CRLF & _
"" & @CRLF & _
"(_)tar<>rap(_)" & @CRLF & _
")()_<(*&bab&*)>_))(" & @CRLF & _
")(*?*)(." & @CRLF & _
"()<-<oxxo>_>()" & @CRLF & _
"<__>w(ow(wo)w<__>" & @CRLF & _
"at<()((<oyo>))()>t)a"
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