#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mx)(# the number at the beginning" & @CRLF & _
"[-+]? # optional leading sign" & @CRLF & _
"\d+# the digits to the left of the decimal" & @CRLF & _
"(?:\.\d+)? # an optional decimal amount" & @CRLF & _
")" & @CRLF & _
"" & @CRLF & _
"(#the start of the units" & @CRLF & _
" [a-zA-Z]+ # must be alphabetic" & @CRLF & _
" (?: # followed optionally by zero-or-more" & @CRLF & _
" \/[a-zA-Z]+ # slash-followed-by-text as in /hr" & @CRLF & _
" |" & @CRLF & _
" \^[-+]?\d+(?:\.\d+)? # a caret followed by our same/initial digit pattern" & @CRLF & _
" )*" & @CRLF & _
")"
Local $sString = "Very much a stupid beginner question, but trying to make a regex expression which would take in "5ms-1", "17km/h" or "9ms^-2" etc. with these ambiguous units and ambiguous formats. Please help, I can't manage it" & @CRLF & _
"" & @CRLF & _
"-5mph" & @CRLF & _
"6.8m/h" & @CRLF & _
"+8liters/hectacre^2" & @CRLF & _
"" & @CRLF & _
""
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