#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "\b([A-PR-UWYZ](?:(?:\d{1,2}|\d[A-HJ-KSTUW])|(?:[A-HK-Y]\d(?:\d|[A-Z])?)))\s?(\d[ABD-HJLNP-UW-Z]{2})\b"
Local $sString = "DD81UN" & @CRLF & _
"DD8 1UN" & @CRLF & _
"" & @CRLF & _
"DN551PT" & @CRLF & _
"DN55 1PT" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"AN NAA M1 1AA" & @CRLF & _
"ANN NAA M60 1NW" & @CRLF & _
"AAN NAA CR2 6XH" & @CRLF & _
"AANN NAA DN55 1PT" & @CRLF & _
"ANA NAA W1A 1HQ" & @CRLF & _
"AANA NAA EC1A 1BB" & @CRLF & _
"" & @CRLF & _
"DD8 2CA" & @CRLF & _
"DD8 2AA" & @CRLF & _
"DD8 2IA" & @CRLF & _
"DD8 2KA" & @CRLF & _
"DD8 2MA" & @CRLF & _
"DD8 2OA" & @CRLF & _
"DD8 2VA" & @CRLF & _
"DD8 2aa" & @CRLF & _
"" & @CRLF & _
"AN" & @CRLF & _
"ANN" & @CRLF & _
"ANA" & @CRLF & _
"AAN" & @CRLF & _
"AANN" & @CRLF & _
"AANA" & @CRLF & _
""
Local $sSubst = "$1 $2"
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