#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "\{(?:(?:\{(?:(?:\{(?:[^{}])*\})|(?:[^{}]))*\})|(?:[^{}]))*\}"
Local $sString = "captures up to singly-nested blocks:" & @CRLF & _
" p{1} = \{(?:[^{}])*\}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"int main() {" & @CRLF & _
"" & @CRLF & _
" return 0;" & @CRLF & _
"" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"captures up to doubly-nested:" & @CRLF & _
" p{2} = \{(?:(?:p{1})|(?:[^{}]))*\}" & @CRLF & _
" ...or..." & @CRLF & _
" p{2} = \{(?:(?:\{(?:[^{}])*\})|(?:[^{}]))*\}" & @CRLF & _
"" & @CRLF & _
"void more_complex_fxn(int z) {" & @CRLF & _
" int x = z / 9;" & @CRLF & _
" if (x > 3) {" & @CRLF & _
" do_something;" & @CRLF & _
" x += 5;" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"Following the pattern set above..." & @CRLF & _
"" & @CRLF & _
"up to triply-nested:" & @CRLF & _
" p{3} = \{(?:(?:p{2})|(?:[^{}]))*\}" & @CRLF & _
" ...or..." & @CRLF & _
" p{3} = \{(?:(?:\{(?:(?:\{(?:[^{}])*\})|(?:[^{}]))*\})|(?:[^{}]))*\}" & @CRLF & _
"" & @CRLF & _
"double so_many_blocks(double x) {" & @CRLF & _
" double y = x;" & @CRLF & _
" while(y > 4) {" & @CRLF & _
" if (y < 6) {" & @CRLF & _
" y -= 0.3;" & @CRLF & _
" } else {" & @CRLF & _
" y -= 0.5;" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
" return y;" & @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