#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^(?!\d+$)(([1-9]\d*)?[Dd]?[1-9]\d*( ?[+-] ?)?)+(?<![+-] ?)$"
Local $sString = "**WORKS**" & @CRLF & _
"d20" & @CRLF & _
"2D12+ 4 - 2" & @CRLF & _
"12d4-2d6+7 + d8" & @CRLF & _
"7 + 1d12" & @CRLF & _
"" & @CRLF & _
"**DOESN'T WORK**" & @CRLF & _
"-2d6+4" & @CRLF & _
"-d8 - 5" & @CRLF & _
"12" & @CRLF & _
"2d0 + 5" & @CRLF & _
"1d6 + 0d2 - 1" & @CRLF & _
"0d6" & @CRLF & _
"100d" & @CRLF & _
"d" & @CRLF & _
"7d4+" & @CRLF & _
"1+"
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