[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Find and repalce a specific word within parentheses

Posted on 2011-04-29
Medium Priority
Last Modified: 2012-08-13
I need to replace a specific word within closed parentheses in MS word 2010 with another word. I can find any character within parentheses using wildcards in FR : \(*\)

Then, what I need to do is find exactly the word "and" and replace it with an ampersand character "&". Not the string "and" but the specific word "and", which is always preceded by and followed with one or more words (in other words, is always [single space]"and"[single space] (or more generally [whitespace]"and"[whitespace]).

Also, the expression \( and \) doesn't work since it find all instances of the pattern whether or not it is between closed parentheses, if that makes any sense. \(*[ and ]*\) selects the entire phrase, e.g., "(you and I)", not just the word "and".

Sorry, I don't know how "storage zone" was selected, I meant the question to only be in MS Word.

Question by:orerockon
  • 3
LVL 76

Expert Comment

ID: 35493049
With 'Use wildcards' ticked, try

Find:  (\(*)<and>(*\))

Replace: \1&\2

Expert Comment

ID: 35493949
Use the space befor and after the word and as well as the replacement ampersand.

Find: and
Replace with: & 


Author Comment

ID: 35494223
Graham: It works, but it doesn't find only " and " within closed parentheses: "( and )". For example, it also finds:

"(A) and (B) " so it is finding " and " between two sets of closed parentheses, not within one set.
LVL 76

Expert Comment

ID: 35494416
Wildcard Finds cannot always be guaranteed not to find spurious examples. It is often a matter of tuning to the best fit.

I will do some more experiments.
LVL 76

Accepted Solution

GrahamSkan earned 2000 total points
ID: 35496714
I cannot find a way of doing it in a single Find.

Here is a VBA macro instead.
Sub ToAmpersand()
    Dim rng As Range
    Dim rng2 As Range
    Set rng = ActiveDocument.Range
    With rng.Find
        .MatchWildcards = True
        .Text = "\(*\)"
        Do While .Execute
            Set rng2 = rng.Duplicate
            With rng2.Find
                .MatchWildcards = True
                .Text = "<and>"
                .Replacement.Text = "&"
                .Execute Replace:=wdReplaceAll
            End With
    End With

End Sub

Open in new window


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question