#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?(DEFINE)(?'comment'\/\*(?!\*\/)[\/s\/S]*?\*\/|\/\/.*+)" & @CRLF & _
" (?'quoted_string'\"[^\"]*\")" & @CRLF & _
" (?'id'\b[a-zA-Z_]\w*+\b)" & @CRLF & _
" (?'id_alias'(?&id))" & @CRLF & _
")(?&comment)(*SKIP)(*F)|(?"ed_string)(*SKIP)(*F)|(?&id_alias)"
Local $sString = "// function example" & @CRLF & _
"#include <iostream>" & @CRLF & _
"using namespace std;" & @CRLF & _
"" & @CRLF & _
"int addition (int a, int b)" & @CRLF & _
"{" & @CRLF & _
" int r;" & @CRLF & _
" r=a+b;" & @CRLF & _
" return r;" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"int main ()" & @CRLF & _
"{" & @CRLF & _
" int z;" & @CRLF & _
" z = addition (5,3);" & @CRLF & _
" cout << "The result is " << z;" & @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