#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)(?:^|\b)(?<number>(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?)(?<replace> ?|&[^;]{2,7};)(?<dimensions>(?<mathjax>\$[^\n\$]+\$)|(?<unit>(?<si>(?!as)(?:[QRYZEPTGMkhdcmµnpfazyrq]|da)?(?:mol|cd|Hz|Pa|Wb|lm|lx|Bq|Gy|Sv|kat|[mgsAKNJWCVFΩSTHL]))|(?<imperial>mil|P|in|ft|yd|mi|le|ftm|nmi|oz|lbs?|t|tsp|tbsp|c|fl oz|pt|qt|gal|(?:sq|cu) ?(?:in|ft|yd|mi)|ft-lbf?|lbf?-ft|deg|Btu|psi|Ly)|(?<common>mph|kph|rad|sr)|(?<binary>(?:(?:[KMGTPEZY])i?)?B)))(?=\b|$| |[.,:;()\[\]{}=/*+—–-])"
Local $sString = "I have a 30 $m^2$ pumpernickle" & @CRLF & _
"More precisely it's 29.87$m^2$." & @CRLF & _
"Traveling over 4,000 km, to where once there was" & @CRLF & _
"...in the year 2016 as a new method of..." & @CRLF & _
"He crashed at 50mph" & @CRLF & _
"They collided at speeds of over 200m/s" & @CRLF & _
"The reading is 2kHz." & @CRLF & _
"The range is 20kHz–1MHz (1,000.3 kHz)." & @CRLF & _
"Just 4M words at 30MB."
Local $sSubst = "$<number> $<dimensions>"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
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