You can do this by cut+paste to another RTF editor that supports them, but this does all kinds of horrid things if you want to reimport the text, like mess up tracked changes. Is there something like a plug-in that does this, or some feature that I am missing?

Postscript The PCRE functionality I miss most, from most missed to only rarely missed, are:

  1. Match against vertical whitespace - Word has some facility here, but it is limited;
  2. Zero-width expressions;
  3. Test for Unicode properties;
  4. Backreferences; and
  5. Non-greedy matches.
  • "Match against vertical whitespace - Word has some facility here, but it is limited;" How are you doing that? – barlop Dec 23 '11 at 21:59

The wildcards in Microsoft Word are bit like Regular Expressions. This article has more detail.

Standard Regular Expressions compare to Word Regular Expressions as follows:

  • . becomes ?
  • .* becomes *
  • * becomes @ - e.g. lo@t matches lot and loot
  • [] works the same in both
  • () works the same in both
  • \ escapes wildcards in both
  • \b becomes < and > for matching word boundaries
  • These are very useful, and are good enough for most tasks. But they lack a lot PCRE functionality. I'll edit my post accordingly. – Charles Stewart Jan 19 '10 at 11:44
  • Naturally they lack PCRE functionality. I've been watching this question since it first appeared, thinking 'Perl Compatible Regular Expressions' in Word, you've got to be joking! Still, I've been wrong before (notably about Javascript support in PDF files) but I think a third party would have to add PCRE to Word, and PCRE suits text files, not the (basically) binary format of Word documents. – pavium Jan 19 '10 at 12:49
  • No, I think not: you can generalise most PCREs to the kind of regexp Word has, and then narrow that list to the ones that really match, using outside code. But this is a nontrivial coding task... I could ask on SO if no-one has any more straightforward ideas. – Charles Stewart Jan 19 '10 at 17:03
  • I'm accepting this, because I'm fairly sure now that the answer is "no", and that this is the best that can be said without new software being written. – Charles Stewart Feb 17 '10 at 9:22

You could probably write a VBA macro. Internet Explorer 5.5 shipped with a reasonably decent regex engine for use with VBscript. That same engine can also be used in VBA macros on any computer that has MS Office and IE 5.5+ installed - which should be pretty much any Windows machine by now.

To use the regex objects in VBA macros, you need to add a reference to the VBScript regex engine in the VBA editor. Load up the VBA macro editor, and select Tools->References from the menu. Find "Microsoft VBScript Regular Expressions 5.5" in the list of available references and tick it.

Then you can write macros which process the text directly in Word (like any other Word macro), using the RegExp object from the VBScript_RegEx_55 library to actually do the regex-based matching and replacements. It's not quite as easy as using a dialogue box directly, but it's not terribly difficult. If you know enough about programming to actually use regexes, I'm sure you'd be able to handle the VBA coding.

http://www.regular-expressions.info/vb.html has some info on how to actually use the RegEx objects provided in that library.

  • I think the VBScript regexp object provides the same kind of regexp as that from VBA.NET, which I know can be accessed from Word 2007 onwards. – Charles Stewart Mar 26 '12 at 12:15

This website lists all the wildcards, meta-characters and caveats of Find & Replace in Word.

An important difference between Word and PCRE is that the carat ^ has a very different meaning. Carats are used to make metacharacters, like ^p for paragraph.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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