#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^(\d{3}) .*(?:\r?\n\1.*)*"
Local $sString = "021 Line one of section A. " & @CRLF & _
"021 Line two of Section A. " & @CRLF & _
"021 Line three of section A. " & @CRLF & _
"021 Part two of Line three of Section A. " & @CRLF & _
"021 We just skipped line four, but that's okay. " & @CRLF & _
"021 Back to line six. " & @CRLF & _
"Non-formatted lines to be ignored. This can be from 0 lines, to any number of lines, and the content can be any text. " & @CRLF & _
"033 Line 1 of Section B " & @CRLF & _
"033 Line 2 of Section B " & @CRLF & _
"033 Okay, that's enough."
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