#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^@ heading2$[\s\S]*?^(?:field2: \"?((?<=\")[^"\\]*(?:\\.[^"\\]*)*(?=\"$)|(?<!\").*(?!\")$)\"?$|)?$[\s\S]*?(?=@ [^\s]*?|\Z)"
Local $sString = "@ heading1" & @CRLF & _
"field1: "single-line strings are quoted only sometimes."" & @CRLF & _
"field2: "strings that span" & @CRLF & _
"multiple lines" & @CRLF & _
"are always quoted."" & @CRLF & _
"field3: this single-line string is unquoted." & @CRLF & _
"" & @CRLF & _
"@ heading2" & @CRLF & _
"field1: field names can be repeated among headings." & @CRLF & _
"field2: "Regex is harder when I add an" & @CRLF & _
"@ in a multi-line string, or if I add" & @CRLF & _
"backslash-escaped characters like \" and \'." & @CRLF & _
"" & @CRLF & _
"What happens if I have an empty line in a string?" & @CRLF & _
"" & @CRLF & _
"Also," & @CRLF & _
"[this line]" & @CRLF & _
"isn't actually a section."" & @CRLF & _
"field3: this field comes after field2" & @CRLF & _
"[sectionname]" & @CRLF & _
"field1: the same field name under a different section." & @CRLF & _
"[anothersection]" & @CRLF & _
"field1: a second section under the same heading" & @CRLF & _
"field4: field number four" & @CRLF & _
"" & @CRLF & _
"@ heading3" & @CRLF & _
"field1: value value value value value" & @CRLF & _
"field2: "quoted string" & @CRLF & _
"quoted string" & @CRLF & _
"quoted string"" & @CRLF & _
"unique: unique field name"
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