#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?ms)AND op.OP(\d{1,2})(OPVerfahren.*?\))"
Local $sString = " AND op.OP1OPVerfahren > 0" & @CRLF & _
" AND p.Testzwecke = 0" & @CRLF & _
" AND NOT EXISTS (SELECT DISTINCT 1 FROM ods01.dat_optherapie op2 WHERE op2.patID = p.ID AND op2.revision > op.revision)" & @CRLF & _
" UNION ALL" & @CRLF & _
"" & @CRLF & _
" AND op.OP2OPVerfahren > 0" & @CRLF & _
" AND p.Testzwecke = 0" & @CRLF & _
" AND NOT EXISTS (SELECT DISTINCT 1 FROM ods01.dat_optherapie op2 WHERE op2.patID = p.ID AND op2.revision > op.revision)" & @CRLF & _
" UNION ALL"
Local $sSubst = "AND op.OP$1$2 \n GROUP BY OP$1OPVerfahren"
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