by pietzcker » Thu May 21, 2009 3:11 pm
This sounds like you don't need a macro at all - just one single search and replace routine, using a Perl regular expression.
Open the "Replace" dialog, check the checkbox "Regular Expressions" and set the radio button "Perl regular expression" in the "Advanced" section of that dialog. Then search for
(?s)\bword1\b.*?\bword2\b
and replace all with nothing.
Caution: This fails if word1/word2 pairs can be nested (e. g., "word1 text text word1 text text word2 text text word2")
Also caution if your "word1/2" contains characters that are special to regular expressions like .*[]\+? and a few others. In that case, please be more specific about your exact words.
Explanation:
(?s) allows searches to span multiple lines
\b matches a word boundary, so if your word1 is "cat", only "cat" will match and not "advocate"
. matches any character (including newlines, thanks to (?s) above)
* allows for any number of matches (including zero)
? makes the * lazy so that it will only match as much as is absolutely necessary. This is mandatory because otherwise, in the text "word1 deletethis word2 dontdeletethis word1 deletethis word2" the regular expression would match from the very first word1 to the very last word2, deleting everything in-between.
HTH,
Tim