Keep single wildcard character unchanged when using Find and Replace in Word


When using the single-character wildcard ("?") in the Find & Replace box in Word, is there a way to leave the "single-character" unchanged during a multiple-instance replacement?

For example, suppose you have a lengthy document in which you want to [Replace All] strings consisting of a space followed by any single letter followed by a period followed by another space, ie:


where each underscore represents a space (just for the purposes of this post) and the x represents any single character.

And suppose you want to replace each of those strings with the following:


In other words, say you want to replace the period in the first string with a vertical bar but leave the single letter unchanged. Is there a way to do that?

I tried it using the single-character wildcard ("?") in both the Find and Replace field but that doesn't work so I'm curious to know if there is a workaround.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It is possible without a sample document, but it is always helpful to provide one. It reduces the work that the experts have to do to create an accurate one, and it increases the certainty that we understand the problem. Thank you.
Are there any restrictions on what the single character can be? For example, is another space acceptable?
Find: _(?)._
Replace: _\1|_
As in your convention, "_" represents a space.

The () brackets define a particular string in the Find part.
The \1 repeats the string found within the first pair of brackets in the find string. Any subsequent such strings can be defined by \2, \3, etc,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference ithrough the Colors of STEM program.

WeThotUWasAToadAuthor Commented:
Thanks a bunch Graham. This is awesome! I only wish I would have posted this question a long time ago. :P I'm always amazed at how much can be accomplished using just the Find and Replace box (in both Word & Excel) and this is a super addition to my toolkit. is always helpful to provide [a sample document]
Apologies for not including a sample doc. I actually thought about attaching something but I cannot post the doc to which I referred (due to its size and confidential content) and anything else, it seems, would have contained only a few strings, ie:


which I figured someone would likely create on their own if needed, rather than downloading and opening an attachment.

Are there any restrictions on what the single character can be? For example, is another space acceptable?
I was thinking only in terms of the 26 letters in the alphabet, not a space or other character.


I misinterpreted the next statement at first glance so these next notes do not contain a question but are just for my own future reference:
Any subsequent such strings can be defined by \2, \3, etc,
"subsequent such strings" is not referring to subsequent strings in the document but to subsequent strings in the Find and Replace arguments. For example,

Find what: _(?)._
Replace with: _\1|_

preserves a single character for every occurrence in a document even though the characters may be different (which is the whole point of this thread) so:

    {_A._ ; _B._ ; _C._ ; _D._ ; _E._} becomes {_A|_ ; _B|_ ; _C|_ ; _D|_ ; _E|_}


Find what: A B (*) 6 7 (?) 9
Replace with: A B \1 F G \2 I

    changes {A B C D E 6 7 H 9} to {A B C D E F G H I}

Note that it also works with * for multiple-character strings.
WeThotUWasAToadAuthor Commented:
Thanks again!
Thank you for your feedback.
Yes, it was easy to create a document. Questions can be somewhat ambiguous and a sample document can help to clarify. In this case your description was good.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.