#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)(?m)(?P<head>^tacacs[\s|-]server\shost\s)(?P<ipv4>(\d+\.){3}\d+)(?P<key>\skey\s[0-9]\s\S[a-zA-Z0-9]+\S)?(?P<tail>(.*))"
Local $sString = "aaa group server tacacs+ tacacs" & @CRLF & _
" server 172.26.60.235" & @CRLF & _
" server 172.24.248.209" & @CRLF & _
" source-interface mgmt0" & @CRLF & _
"aaa group server tacacs+ TACACS-GROUP" & @CRLF & _
" server 172.26.60.235" & @CRLF & _
" source-interface mgmt0" & @CRLF & _
"aaa group server tacacs+ TACACS-TEST1" & @CRLF & _
" server 172.26.60.235" & @CRLF & _
" server 172.24.248.209" & @CRLF & _
"aaa group server tacacs+ tacacs+group" & @CRLF & _
" source-interface mgmt0" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"ip tacacs source-interface mgmt0" & @CRLF & _
"" & @CRLF & _
"tacacs-server host 172.26.60.235 key 7 "Foihmr3" timeout 5" & @CRLF & _
"tacacs-server host 172.24.248.209 key 7 "Foihmr3"" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"tacacs server host 172.24.248.209 key 7 "Foihmr3"" & @CRLF & _
"" & @CRLF & _
"tacacs-server host 172.26.60.235 timeout 5" & @CRLF & _
"" & @CRLF & _
"tacacs-server host 172.26.60.235" & @CRLF & _
"tacacs-server host 172.24.248.209"
Local $sSubst = ""
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