#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)^(WSPRD2\b.*\r?\n(?:(?!END\b).*\r?\n)*).*\bDELESTAT\b.*\r?\n"
Local $sString = "WSPRD3#/TO/PATH/TASK5" & @CRLF & _
" PRIORITY 60" & @CRLF & _
"NEEDS 1 MASTER#AAA0RTYU" & @CRLF & _
"NEEDS 1 MASTER#DELESTAT" & @CRLF & _
"NEEDS 1 MASTER#RAAA1JK" & @CRLF & _
"" & @CRLF & _
" FOLLOWS GET_INPUT" & @CRLF & _
"" & @CRLF & _
"END" & @CRLF & _
"" & @CRLF & _
"WSPRD2#/TO/PATH/TASK6" & @CRLF & _
" PRIORITY 60" & @CRLF & _
"NEEDS 1 MASTER#AAA0RETU" & @CRLF & _
"NEEDS 1 MASTER#DELESTAT" & @CRLF & _
"NEEDS 1 MASTER#RAAACCC" & @CRLF & _
"" & @CRLF & _
" FOLLOWS GET_INPUT" & @CRLF & _
"" & @CRLF & _
"END" & @CRLF & _
"" & @CRLF & _
"WSPRD4#/TO/PATH/TASK8" & @CRLF & _
" PRIORITY 60" & @CRLF & _
"NEEDS 1 MASTER#AAA0RETU" & @CRLF & _
"NEEDS 1 MASTER#DELESTAT" & @CRLF & _
"NEEDS 1 MASTER#RAAACCC" & @CRLF & _
"" & @CRLF & _
" FOLLOWS GET_INPUT" & @CRLF & _
"" & @CRLF & _
"END" & @CRLF & _
""
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