Link to home
Start Free TrialLog in
Avatar of orerockon
orerockonFlag for United States of America

asked on

Find and repalce a specific word within parentheses

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.

Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

With 'Use wildcards' ticked, try

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

Replace: \1&\2
Avatar of Scown
Scown

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

Find: and
Replace with: & 

Avatar of orerockon

ASKER

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial