#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?ms)\(\s*define\s*(\(.*?\))"
Local $sString = "#lang sicp" & @CRLF & _
"(define (square x) (* x x))" & @CRLF & _
"(define (average x y) (/ (+ x y) 2))" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"; using block scope" & @CRLF & _
"(define (sqrt x)" & @CRLF & _
" ; x is always the same -- "4" or whatever we pass to it, so we don't need that" & @CRLF & _
" ; in every single function that we define, we can just inherit it from above." & @CRLF & _
" (define (improve guess) (average guess (/ x guess)))" & @CRLF & _
" (define (good-enough? guess) (< (abs (- (square guess) x)) 0.001 ))" & @CRLF & _
" (define (sqrt-iter guess) (if (good-enough? guess) guess (sqrt-iter (improve guess))))" & @CRLF & _
" (sqrt-iter 1.0)" & @CRLF & _
")" & @CRLF & _
"(sqrt 4)" & @CRLF & _
"" & @CRLF & _
"(define (inc x) (+ x 1))" & @CRLF & _
"(define (dec x) (- x 1))" & @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