• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Advanced Word Hacks > 82. Perform Power Text Searches with Regular Expressio...

Perform Power Text Searches with Regular Expressions

When wildcards just aren’t enough, tap VBScript for powerful string searching in Word.

Although Word’s wildcard searching is much better than most users realize, if you’ve previously used a language like Perl, Python, or JavaScript, you might prefer sticking with the special characters you already know for your searches. Besides, sometimes wildcards just aren’t up to the job.

To borrow an example from O’Reilly’s Learning Python, suppose you need to replace any occurrence of “red pepper” or “green pepper” with “bell pepper” if and only if they occur together in a paragraph before the word “salad,” but not if they are followed (with no space) by the string “corn.” That’s definitely way out of Word’s wildcards’ league. (The pattern is \b(red|green)(\s+pepper(?!corn)(?=.*salad)), for those of you too impatient to wait until the full example at the end of this hack.)


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint