#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?mi)(?<!\-)\[.+?\](\.\w{3}$)"
Local $sString = "SampleFileA-[SortCode].xls" & @CRLF & _
"SampleFileB-[SortCode][CRCNum].xls" & @CRLF & _
"SampleFileC-[SortCode][OtherSortCode][CRCNum].xls" & @CRLF & _
"SampleFileD-Date[CRCNum].xls" & @CRLF & _
"SampleFileE-Date.xls" & @CRLF & _
"" & @CRLF & _
"In this example I only want to remove [CRCNum] from the file names." & @CRLF & _
"" & @CRLF & _
"This is as close as I can get. I just don't know how to use lookbehind properly"
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