Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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 Jun 10 '13 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 Jun 10 '13 at 13:38
1  
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 Jun 10 '13 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 Jun 13 '13 at 12:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.