#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?sx)(?(DEFINE)" & @CRLF & _
" (?<curly> \{ \g<content>*? \} )" & @CRLF & _
" (?<square> \[ \g<content>*? \] )" & @CRLF & _
" (?<pascal> \bbegin\b \g<content>*? \bend\b )" & @CRLF & _
" (?<lua> --\[ \g<content>*? --\] )" & @CRLF & _
"" & @CRLF & _
" (?<nested> \g<curly> | \g<square> | \g<pascal> | \g<lua> )" & @CRLF & _
"" & @CRLF & _
" (?<content>" & @CRLF & _
" # Math non-recursive content (atomically)" & @CRLF & _
" (?: (?! [{}\[\]] | \bbegin\b | \bend\b | --[\[\]] ) .)++" & @CRLF & _
" # Or recurse" & @CRLF & _
" | \g<nested>" & @CRLF & _
" )" & @CRLF & _
")" & @CRLF & _
"" & @CRLF & _
"\g<nested>"
Local $sString = "EVENLY BALANCED curly braces" & @CRLF & _
"" & @CRLF & _
"{{{}}}" & @CRLF & _
"{ test1 { test2 { test3 { test4 } } } }" & @CRLF & _
"" & @CRLF & _
"UNEVENLY BALANCED curly braces" & @CRLF & _
"{{{{}}} end <-- this is needed, otherwise this line balances with the line below :)" & @CRLF & _
"{ test1 { test2 { test3 { test4 } } } } }" & @CRLF & _
"" & @CRLF & _
"MULTI-LINE EVENLY BALANCED curly braces" & @CRLF & _
"{" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"MULTI-LINE UNEVENLY BALANCED curly braces" & @CRLF & _
"{{" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"EVENLY BALANCED square braces" & @CRLF & _
"[ test1 [ test2 [ test3 [ test4 ] ] ] ]" & @CRLF & _
"" & @CRLF & _
"EVENLY BALANCED square and curly braces" & @CRLF & _
"{ test1 [ test2 { test3 [ test4 ] } ] }" & @CRLF & _
"" & @CRLF & _
"UNEVENLY BALANCED square and curly braces" & @CRLF & _
"{ test1 [ test2 { test3 [ test4 ] } } ]" & @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