#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?im)(?<=^ *)(?=\$(?:\{[a-z_][a-z0-9_]*\}|[a-z_][a-z0-9_]*)|[a-z_][a-z0-9_]*)(?:(?:\$\{)?([^ \}]+)\}?)(?= *$)"
Local $sString = "### INFO" & @CRLF & _
"# Attempt to capture a parameter identifier inside a text selection, possibly" & @CRLF & _
"# wrapped in whitespace, including the following (examples using `backtick quotes`):" & @CRLF & _
"# - Raw word: e.g. `param_name`" & @CRLF & _
"# - $parameter expansion: e.g. `$param_name`" & @CRLF & _
"# - ${parameter} expansion e.g. `${param_name}`" & @CRLF & _
"### ENDINFO" & @CRLF & _
"" & @CRLF & _
"testvar" & @CRLF & _
" testvar" & @CRLF & _
" test_var " & @CRLF & _
" test5_var " & @CRLF & _
" test_var5 " & @CRLF & _
" $test_var" & @CRLF & _
" $test_var4" & @CRLF & _
" ${test_var4}"
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