0

Using Word 2013 ...

Say I have a document that has lots of instances of similar but not exactly the same text between paragraph marks, like so:

text text text ¶

somethingXYZsomething¶

text text text ¶

stelseXYZstelse ¶

text text text¶

thirdXYZthird¶

text text text¶

... and so on.

I want to replace the lines that have "XYZ" in them with a pair of paragraph marks ¶¶ (or, to put it another way, to delete all the text on that line).

My initial effort was to use Find/Replace with wildcards and the following (assume "XYZ" does not have to be case sensitive).

Find: ^13*xyz*^13

Replace with: ^p^p

Unfortunately, Word starts with the first ¶ it encounters and selects all the text through the next "XYZ" (including intervening paragraphs) and then proceeds until the next ¶ after "XYZ."

I looked around and did not see a way to say "the nearest ¶ to the given string."

Any ideas?

Thanks!

1 Answer 1

0

You can exclude non ^13 characters between two ^13 in your search like this:

^13[!^13]@XYZ[!^13]@^13

@ means "one or more occurrences of the previous character" and ! (exclamation mark) excludes characters inside brackets. The problem is that none of "XYZ", " XYZ", "XYZ " will match so before using this replace "XYZ" with " XYZ ". Unfortunately there is no way to tell Word "zero or more occurrences of the previous character".

1
  • Just copying your find string did exactly what I wanted because I didn't have any "naked" strings of XYZ. I see what you mean that it doesn't work unless there is something between the target string and the ¶ marks on both sides. But even in that case, two steps is better than hundreds. Thanks very much!
    – vknowles
    Commented Feb 3, 2020 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .