#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?x) (?s)" & @CRLF & _
" <page>" & @CRLF & _
" ( " & @CRLF & _
" .*? " & @CRLF & _
" (?:" & @CRLF & _
" (?: <page> | </page> )" & @CRLF & _
" (*SKIP) (*FAIL) " & @CRLF & _
" | {{Infobox" & @CRLF & _
" )" & @CRLF & _
" .*? " & @CRLF & _
" ) " & @CRLF & _
" (?: <page> (*SKIP) (*FAIL) | </page> )" & @CRLF & _
""
Local $sString = "List of keywords :" & @CRLF & _
"" & @CRLF & _
"keyword1 = <page>" & @CRLF & _
"keyword2 = </page>" & @CRLF & _
"keyword3 = {{Infobox" & @CRLF & _
"" & @CRLF & _
"Example A:" & @CRLF & _
"" & @CRLF & _
"<page>" & @CRLF & _
"text to consider without {{ not-Infobox" & @CRLF & _
"</page>" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"Result => do not extract (or keep or split) this part." & @CRLF & _
"" & @CRLF & _
"Example B:" & @CRLF & _
"" & @CRLF & _
"<page>" & @CRLF & _
"text to consider with {{Infobox here}}" & @CRLF & _
"</page>" & @CRLF & _
"" & @CRLF & _
"Result => extract (or keep or split) this part."
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