6

I would like to "Find and Replace" entire lines in Microsoft Office Word 2010 which match some criteria.

I tried to find the solution in the official documentation, but I didn't find the answer:

(btw. here are two more useful unofficial documents: Find and Replace using wildcards; Regular Expressions in Microsoft Word)


Example

For example: I would like to search for all the lines which have the "Heading 2" style, and replace them so that they get between ## symbols: so this is the original text: This is my title, and I would like to find it and replace it this way: ## This is my title ## (this way I could transform a text's title into a Wiki-compatible heading 2 without any external plugins (EDIT: sorry, in the meantime I realized the MediaWiki-compatible heading 2 style uses == instead of ##, but it doesn't change the main point)).

So after Ctrl+H, checking "Use wildcards", selecting Format > Style > Heading 2, I've tried this and it did NOT work: (*^13>) or (<*^13>), where ^13 matches "Paragraph break / 'carriage' return" (see this) - this made Word search madly, and the GUI got frozen for minutes (!). At the end, it didn't find anything (but I DO have texts with Heading 2 style).

Microsoft Word 2010 - Find and Replace (*^13>) - Not Responding (Use Wildcards checked)

OK, this is not the appropriate pattern, so what would be the appropriate way to search and replace entire lines in Word?

1
  • This would be sooooo much easier if Microsoft found out about this new thing called "regex." For that matter, just adding a "start of line" option to their special things list would be a big help. Commented Dec 12, 2018 at 12:54

2 Answers 2

4

Perhaps I'm missing something, but for some reason I wasn't able to do this in a single search/replace operation:

Steps

  1. Before:

    1

  2. Replace empty string (format Heading 2) with "## ^& ##" (no formatting):

    2

  3. After first replace:

    3

  4. Replace "^p ##" (no formatting) with " ##^p" (no formatting) (be aware that there is a space at the beginning of the replace string!):

    4

  5. After second replace:

    5

4
  • Thanks,this really solves it, with one exception: if I have multiple headers of the same kind after each other, like this: i.imgur.com/tJSFXT2.png; after Find and Replace (sorry, I forgot that in MediaWiki, for parsing headers, I must use == symbols instead of ## symbols, but this doesn't change the main point), Word places == symbols like this: i.imgur.com/aHABiBF.png, and after the 2nd replace, like this: i.imgur.com/HkBGRib.png, which means I have to put an empty line between each of them first!:)
    – Sk8erPeter
    Commented Jun 10, 2013 at 13:37
  • But I could solve my problem with your solution, so thanks, +1 and accepted! ;) This new line "bug" (?) you mentioned is really strange though.
    – Sk8erPeter
    Commented Jun 10, 2013 at 13:38
  • 4
    It seems the ^p at the end of the line is part of the text with style Heading 2. So when you attempt to replace Heading Text with ## <Search String> ##, what actually happens is that Heading Text^p is replaced with ## Heading Text^p ##. Thus the trailing ## ends up on the next line preceded with a space. I don't know how to restrict the search string from including the trailing ^p.
    – Karan
    Commented Jun 10, 2013 at 15:47
  • Yes, this can be the reason, thank you. It would be really good to know how to restrict the search and replace to exclude the newline character. Anyway, you solved it. :)
    – Sk8erPeter
    Commented Jun 13, 2013 at 12:46
-1

I know the question is old, but not finding any practical solutions here or other places, I thought I'd post the answer for posterity's sake.

Perhaps Word has made enhancements to the function that allowed me to perform a single replace operation that did the job the asker described:

Find What: (*{1,})

---Style: Heading 1

Replace With: \1

---Style: Normal

Note that using (*) instead of (*{1,}) eliminated the first character in the line. Apparently, there's some special meaning involved in (*) that I'm not inclined to research.

1
  • Didn't work for me using Word 2013 - I enabled "Use wildcards" and made "Replace with:" ## \1 ##, and the result was ## H #### e #### a #### d #### i #### n #### g ####. With your answer as written with "Use wildcards" checked, it just says "All done, we made xx replacements", but doesn't change any text - obviously because your "Replace with" is just replacing with the entire text to find, so doesn't do anything.
    – localhost
    Commented Feb 4, 2021 at 4:42

You must log in to answer this question.

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