#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)# Section header" & @CRLF & _
"^ \s* \[ \s* \w+ \s* \] \s* $" & @CRLF & _
"" & @CRLF & _
"# Section items" & @CRLF & _
"(?:" & @CRLF & _
" ^ (?:" & @CRLF & _
" # key = value" & @CRLF & _
" \s* \w+ \s* = \s* [\w\s]+ \s*" & @CRLF & _
" |" & @CRLF & _
" # comment line" & @CRLF & _
" \s* \# .* $" & @CRLF & _
" |" & @CRLF & _
" # blank line" & @CRLF & _
" \s*" & @CRLF & _
" ) $" & @CRLF & _
") *"
Local $sString = "[ keybinds ]" & @CRLF & _
"# comment" & @CRLF & _
"bksp = reload" & @CRLF & _
"# comment" & @CRLF & _
"space = jump # not comment" & @CRLF & _
"" & @CRLF & _
" [settings ]" & @CRLF & _
"" & @CRLF & _
"resolution = 640 x 480" & @CRLF & _
"max_framerate = 24" & @CRLF & _
"" & @CRLF & _
"[character]" & @CRLF & _
"# This is a comment. This section is empty." & @CRLF & _
"" & @CRLF & _
"[weapons]" & @CRLF & _
"" & @CRLF & _
"[server]" & @CRLF & _
"login = hexology" & @CRLF & _
"password = my password # is not a comment"
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