#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)\b([A-Z]+)0(?=\d{3}\b)"
Local $sString = "SK0498 should return SK498 (total digits = 4 = omit the single leading zero)" & @CRLF & _
"" & @CRLF & _
"AA007 should still return AA007 (because the leading zeros are double, and total digits is only 3)" & @CRLF & _
"" & @CRLF & _
"UA2138 returns UA2138 (no leading zeros involved)" & @CRLF & _
"" & @CRLF & _
"BA023 should return BA023 (keep the zero because total number of digits is only 3), however BA0234 should return BA234 (total digits is 4 with a single leading zero that should be omitted)." & @CRLF & _
"AA0007"
Local $sSubst = "$1"
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