Can't find and replace with wildcards

D

Derek Jones

I'm trying to use Find and Replace to delete any phrase in
a document surrounded by parentheses. I'm able to locate
the individual parentheses by using the ASCII codes (^0040
and ^0041) However, when I try to combine this with
wildcard characters (I entered <(^0040)*(^0041)> in the
Find what box.), it tells me that the Pattern match
expression is not valid. What gives?

Derek Jones
Software Support Specialist
Shenandoah University
Winchester, VA
 
A

Alan

Hi Derek:

The way I'd handle those parens is to precede them by a
backslash, and apparently also it can be a good idea to
bracket the expression. This is in lieu of using ASCII
codes.

Thus the open paren becomes [\(]
and the closing one becomes [\)]

So: if you only have simple parens (no parens within
parens) you can do
[\(](*)[\)]
becomes
nothing

If you do have some expressions such as ( ( )) then
it's more work. The above search will find from the first
through the third piece of punctuation.

One possibility: create a Character Style, call it Marker.
Then:
[\(](*)[\)]
becomes
StartPhrase\1EndPhrase
Style: Marker

Now you can do a regular search for
(
Style: Marker

And this should point out the places where you have or had
parens within parens. You have the text
expressions "StartPhrase" and "EndPhrase" so you know what
the whole phrase is, or most of it. Deal with these
individually.

Then you can go
empty slot
Style: Marker
becomes
empty slot
No Formatting

to strip out the simple paren'ed expressions.
* * *
One more thing: you'll be left with some instances of
extra spaces. A wildcard search for [!.:] (that's
two spaces after the close bracket) will find these, for
the most part.
(If you get an error message, clear out the bottom slot of
the "Replace With" tab.)

You might want to play around with these a little in a
practice document before tackling the actual project.
 
K

Klaus Linke

Additional notes to Alan's reply:

-- Word will evaluate characters entered with their code *before* it does
anything else.
So "<(^0040)*(^0041)>" is the same as "<(()*())>".

I don't find that terribly intelligent. IMO, if you use the code for a
character that corresponds to a wildcard character, Word should treat it as
if it had been escaped.
I did ask (e-mail address removed) to change that behaviour a while back.

-- For Word, a new "word" starts after a bracket.
With the text "pleasant(ly)", Find what = <*> will match "pleasant" and
"ly".
So the anchors "<" and ">" seem redundant.

-- The wildcard * is rather dangerous.
In case there is a missing closing brace somewhere in the document, \(*\)
will match anything from the opening brace up to the next closing brace
(potentially down a few chapters of text).
To be on the safe side, you can restrict the matched text, for example using
"\([!\(]@\)".
This "Find what" expression would for example also match only the inner
braces in "(...(...)...)".

Greetings,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top