#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?s).*?course: (\w+)(?:(?!\bcourse\b).)*MyName\s+(\d+).*?"
Local $sString = "sometext" & @CRLF & _
"somemore text here" & @CRLF & _
"" & @CRLF & _
"some other text" & @CRLF & _
"" & @CRLF & _
" course: course1" & @CRLF & _
"Id Name marks" & @CRLF & _
"____________________________________________________" & @CRLF & _
"1 student1 65" & @CRLF & _
"2 student2 75" & @CRLF & _
"3 MyName 69" & @CRLF & _
"4 student4 43" & @CRLF & _
"" & @CRLF & _
" course: course2" & @CRLF & _
"Id Name marks" & @CRLF & _
"____________________________________________________" & @CRLF & _
"1 student1 84" & @CRLF & _
"2 student2 73" & @CRLF & _
"8 student7 99" & @CRLF & _
"4 student4 32" & @CRLF & _
"" & @CRLF & _
" course: course4" & @CRLF & _
"Id Name marks" & @CRLF & _
"____________________________________________________" & @CRLF & _
"1 student1 97" & @CRLF & _
"3 MyName 60" & @CRLF & _
"8 student6 82"
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