Possible to do a "wildcard replace" in Word?

B

Becca

Hi,

I have a long document in which I need to replace text strings like [n]
(where n can be any number) with <bold>Pn</bold>. That is, I need to
strip off the square brackets and replace them with a preceding
character and change the formatting--but leave the number, which is
variable.

I've found the way to search for the wildcard string with the square
brackets, so I've got that part down--it's just the replace I can't
figure out.

I'm clumsy at recording macros, and completely ignorant about Word
Basic and Visual Basic, though I have found the FAQ at
http://word.mvps.org/FAQs/.

Thanks,
Rebecca Freed
 
E

Elliott Roper

Becca said:
Hi,

I have a long document in which I need to replace text strings like [n]
(where n can be any number) with <bold>Pn</bold>. That is, I need to
strip off the square brackets and replace them with a preceding
character and change the formatting--but leave the number, which is
variable.

I've found the way to search for the wildcard string with the square
brackets, so I've got that part down--it's just the replace I can't
figure out.

I'm clumsy at recording macros, and completely ignorant about Word
Basic and Visual Basic, though I have found the FAQ at
http://word.mvps.org/FAQs/.

That was an interesting question.
Here is an answer
You can do it
Your search string should be
\[([0-9]@)\]
and the replace string should be
P\1
Before doing it, hit the replace format style and choose 'strong' -
that will bold the result.
The search string looks for [ with \[ since a [ is a wildcard character
and needs 'escaping' with the \ so Word knows to take the [ literally.
It then looks for one or more digits in the range 0-9 That's [0-9]@
which is enclosed in parentheses so that it will be known as the first
replace string aka \1. Finally the closing square bracket is specified
with \]

The replace string is simply P followed by whatever is found by [0-9]@.

To find that out, believe it or not, I used Word help.
(I am famous for bashing help in this forum)
the magic to search for was
'wildcard replace'
in the offered list "fine tune a search by using wildcard characters"
... and the well-hidden stuff for replace is found by clicking on
"type a wildcard character" inside that article.
then, in the second note, at the very bottom of *that*....

Now you see why I'm famous for rubbishing 'help'? It needs to be
rubbished at every opportunity.
 
B

Becca

Hey, I tried it, and it works! Very cool, and thank you very much.
It's going to save me a lot of time. (Try as I might, I can't get to
that "fine tune a search using wild cards" page in the help file.)

Becca
 
E

Elliott Roper

Becca said:
Hey, I tried it, and it works! Very cool, and thank you very much.
It's going to save me a lot of time. (Try as I might, I can't get to
that "fine tune a search using wild cards" page in the help file.)

Ah Becca. You are a sweetie. Handing me another chance to bag Word help.
On a plate!

Sometimes I think it is a plot. Have you studied psychology? Operant
conditioning. aka training pigeons to play table tennis. Variable ratio
reinforcement. B F Skinner.
Think two rats in a maze. One says to the other "I think I have this
psychologist trained. If I press this bar, he releases food."

That's Word help.
 
B

Beth Rosengard

Ah Becca. You are a sweetie. Handing me another chance to bag Word help.
On a plate!

Sometimes I think it is a plot. Have you studied psychology? Operant
conditioning. aka training pigeons to play table tennis. Variable ratio
reinforcement. B F Skinner.
Think two rats in a maze. One says to the other "I think I have this
psychologist trained. If I press this bar, he releases food."

That's Word help.

No. that's Word X Help :). You must *both* be in Word X. It's all fixed
in Word 2004. You go from "Advanced Search Methods" to "Use wildcard
characters," "Wildcard characters you can use when searching" and
"Find and replace items by typing codes." It's pretty comprehensive.

--
***Please always reply to the newsgroup!***

Beth Rosengard
MacOffice MVP

Mac Word FAQ: <http://word.mvps.org/MacWordNew/index.htm>
(If using Safari, hit Refresh once or twice ­ or use another browser.)
Entourage Help Page: <http://www.entourage.mvps.org>
 
E

Elliott Roper

Beth Rosengard said:
No. that's Word X Help :). You must *both* be in Word X. It's all fixed
in Word 2004. You go from "Advanced Search Methods" to "Use wildcard
characters," "Wildcard characters you can use when searching" and
"Find and replace items by typing codes." It's pretty comprehensive.

Nope. I could find that in Word X help. Becca, (I don't know what she
is on), could not.

Besides, it takes a fair amount of nerdishness to hit on "wildcard" in
the search string. Try for yourself if you say "wild card"
Try again for things that a normal human might try. "pattern match"?
Sorry.
"grep"? Lots of total missess and a couple of near misses.
"regular expression"? Not bad, but you need a PhD in nerdicity for that
one too.
"find replace"? Not bad. It is one of twenty items

or maybe we could try a natural English question?
"How do I use the found expression in the replace string?"
Try it for yourself. You get about 40 topics, each as relevant as
"the name of a supporting folder for a web page is in another language"
I half expected "Your mountain goat is infertile" to pop out of the
list.

Totally, utterly, hopeless!

Furthermore, a lot of what's in your "quite comprehensive" is wrong.
For instance the {1,} syntax for 1 or more of the previous character or
expression does not work for Becca's expression. It does work for
single characters. Hence I had to use (...)@ for that effect.

I am quite convinced the Skinner variable ratio reinforcement
conditioning is there to train me to lay out more money for Office, in
spite of being bitten by bug ridden bloat so many times before. It
figures that if sometimes it works brilliantly, I will more
unforgettably learn to buy more product than if it worked as advertised
every time from the day I bought it.

For the avoidance of doubt, I'm only semi-serious with these remarks.
There must have been some software with more unusable help, but I can't
for the life of me think of its name. Word is the only help I know that
makes Apple's look good.
 
B

Beth Rosengard

Hi Elliott,


I went back and re-read your first post and now I (think) I understand where
my confusion came from. You said that when you searched under "wildcard
replace," you found a topic called "fine tune a search by using wildcard
characters." That topic doesn't come up for me in Word 2004, whether I
search under "wildcard replace" or anything else to do with wildcards.

Since I never used Word X, I assumed that *all* the wild card search topics
in Help had changed in Word 2004.
Nope. I could find that in Word X help. Becca, (I don't know what she
is on), could not.

Besides, it takes a fair amount of nerdishness to hit on "wildcard" in
the search string. Try for yourself if you say "wild card"

In the Word 2004 Help, I get six results, all but one of which apply.
Try again for things that a normal human might try. "pattern match"?
Sorry.

I would never think of "pattern match." Maybe I'm not normal :). However,
the topic "Word doesn't find the item I'm searching for" does at least
appear in the results, though last of a long list.
"grep"? Lots of total missess and a couple of near misses.

Nothing, but that doesn't surprise me.
"regular expression"? Not bad, but you need a PhD in nerdicity for that
one too.

Right, not bad: "Advanced search methods" is the second of two results.
"find replace"? Not bad. It is one of twenty items

Now I'm confused. Exactly what particular topic are you expecting/hoping to
see? As I said, "fine tune a search using wild cards" doesn't exist any
more. When I search on "find replace," I get 19 results and all of the top
results are potentially relevant.
or maybe we could try a natural English question?
"How do I use the found expression in the replace string?"

Another nerdic way of putting it, don't you think :)?
Try it for yourself. You get about 40 topics, each as relevant as
"the name of a supporting folder for a web page is in another language"
I half expected "Your mountain goat is infertile" to pop out of the
list.

I got only 20 results and the fifth was "Advanced search methods."
Totally, utterly, hopeless!

Furthermore, a lot of what's in your "quite comprehensive" is wrong.

Now *that* I can't argue with.
For instance the {1,} syntax for 1 or more of the previous character or
expression does not work for Becca's expression. It does work for
single characters. Hence I had to use (...)@ for that effect.

I am quite convinced the Skinner variable ratio reinforcement
conditioning is there to train me to lay out more money for Office, in
spite of being bitten by bug ridden bloat so many times before. It
figures that if sometimes it works brilliantly, I will more
unforgettably learn to buy more product than if it worked as advertised
every time from the day I bought it.

For the avoidance of doubt, I'm only semi-serious with these remarks.
There must have been some software with more unusable help, but I can't
for the life of me think of its name. Word is the only help I know that
makes Apple's look good.

Word's Help IS better in 2004. That said, it's still got a ways to go.

Elliott, don't you have an old Mac somewhere with enough grunt to install OS
X and the Office 2004 test drive? Or a friend/colleague with Office 2004
installed that you could play with (Office, not the friend/colleague, though
that might be fun too :)? I understand not wanting to risk screwing up
your primary machine, but there must be some other way.

Cheers,

Beth
 

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