Skip to main content

Replace find-and-replace with regular expressions in Microsoft Word

A regular expression is a combination of literal and wildcard characters that you use to find and replace patterns of text.

Microsoft Office Word provides a set of wildcard characters that you can use to build regular expressions, you can use regular expressions to find text that matches a given pattern and then replace those matches with new text.

Some example of using RE in MS Word:

w[io]n finds "win" and "won" but not "worn," because the "r" is not specified.

[r-t]ight finds "right" and "sight." The ranges you specify must be in ascending order. In other words, you can specify [a-m], but not [m-a].

fe{1,}d finds "fed" and "feed." (At least n occurrences of the previous character or expression)

s?t finds "sat" and "set." This character also finds the chosen combination of characters within a word. For example, it could locate "set" within "inset."

Here's a practical example of using regular expressions for transposing dates:

Search replaces 28th May, 2003 with May 28, 2003.

1. Copy and paste the following date into your document: 28th May 2003
2. Open the Find and Replace dialog box, and enter the following expression in the Find what box: ([0-9]{1,2})([dhnrst]{2}) (<[ADFJMNOS]*>) ([0-9]{4}) Make sure you insert a space between the following opening and closing parentheses: 2}) (<[ and *>) ([0.
3. Enter the following expression in the Replace with box (make sure you insert a space between each set of characters), and then click Replace All: \3 \1, \4

More Resources on using Regular Expressions in Microsoft Office Word 97, 2000, and 2002:

 Putting regular expressions to work in Word
 Microsoft Office Assistance: Add power to Word searches with regular expressions
 Using regular expressions on the MVP FAQ site - Finding and replacing characters using wildcards.
 Jeffrey Friedl's book Mastering Regular Expressions

Popular posts from this blog

How to Download Contacts from Facebook To Outlook Address Book

Facebook users are not too pleased with the "walled garden" approach of Facebook. The reason is simple - while you can easily import your Outlook address book and GMail contacts into Facebook, the reverse path is closed. There's no "official" way to export your Facebook friends email addresses or contact phone numbers out as a CSV file so that you can sync the contacts data with Outlook, GMail or your BlackBerry. Some third-party Facebook hacks like "Facebook Sync" (for Mac) and "Facebook Downloader" (for Windows) did allow you to download your Facebook friends' names, emails, mobile phone number and profile photo to the desktop but they were quickly removed for violation of Facebook Terms of Use. How to Download Contacts from Facebook There are still some options to take Friends data outside the walls of Facebook wall. Facebook offers the Takeout option allowing you to download all Facebook data locally to the disk (include

Digital Inspiration

Digital Inspiration is a popular tech blog by  Amit Agarwal . Our popular Google Scripts include  Gmail Mail Merge  (send personalized emails with Gmail ),  Document Studio (generate PDFs from Google Forms ) and   File Upload Forms ( receive files  in Google Drive). Also see  Reverse Image Mobile Search , Online Speech Recognition and Website Screenshots , the most useful websites on the Internet.

PhishTank Detects Phishing Websites by Digg Style Voting

OpenDNS, a free service that helps anyone surf the Internet faster with a simple DNS tweak , will announce PhishTank today. PhishTank is a free public database of phishing URLs where anyone can submit their phishes via email or through the website. The submissions are verified by the other community members who then vote for the suspected site. This is such a neat idea as sites can be categorized just based on user feedback without even having to manually verify each and every submission. PhishTank employs the "feedback loop" mechanism where users will be kept updated with the status' of the phish they submit either via email alerts or a personal RSS feed . Naturally, once the PhishTank databases grows, other sites can harness the data using open APIs which will remain free. OpenDNS would also use this data to improve their existing phishing detection algorithms which are already very impressive and efficient. PhishTank | PhishTank Blog [Thanks Allison] Related: Google