Wildcard search and replace

B

Bruce

I would like to find instances of "MyCompany" and replace
them with "MyCompany MyState". I have already downloaded
an article by Graham Mayor (from the MVP site, I think),
so if your reply is to refer me to that article, I already
have it, thank you. My general approach has been to
search for "MyCompany (anything other than "MyState")" and
replace it with "MyCompany MyState", but between [], [!],
<>, etc. I have managed to generate quite a variety of
worthless error messages, but have made no progress toward
the desired result.
In some cases "MyCompany MyState" appears in the document,
so simply replacing "MyCompany" with "MyCompany MyState"
will not work in all cases. Another wrinkle is that
sometimes "MyCompany" is followed immediately by a
punctuation mark, so I can't search for "MyCompany " (with
the added space).
Another difficulty I have encountered with wildcard
searches is after I have found, for instance, "MyCompany
is growing" I want to replace it with "MyCompany MyState
is growing", but when I have managed to contrive searches
that find "My Company (something other than "MyState")", I
can't avoid replacing the part that follows "MyCompany".
Backslashes seem to enter into solving this, but I can't
make out how they owrk in the Replace part of the function.
I realize I could do a simpler search, and just skip some
replacements as needed, but I have a project that involves
some very large documents that will require extensive
editing, so I would like to make use of Replace if it has
the capabilities I need.
 
G

Guest

Could you replace all instances of "MyCompany" with "My Company MyState", and then replace all instances of "MyState MyState" with "MyState"?
 
B

Bruce

Thanks for taking the time to reply. Yes, I could do
that. However, with a lot of editing to do I am trying to
learn how to make the most of wildcard searches. My
question is not so much about the situation I outlined as
it is about using the feature effectively enough that I
don't have to review every replacement in a long document.
-----Original Message-----
Could you replace all instances of "MyCompany" with "My
Company MyState", and then replace all instances
of "MyState MyState" with "MyState"?
Bruce said:
I would like to find instances of "MyCompany" and replace
them with "MyCompany MyState". I have already downloaded
an article by Graham Mayor (from the MVP site, I think),
so if your reply is to refer me to that article, I already
have it, thank you. My general approach has been to
search for "MyCompany (anything other than "MyState")" and
replace it with "MyCompany MyState", but between [], [!],
<>, etc. I have managed to generate quite a variety of
worthless error messages, but have made no progress toward
the desired result.
In some cases "MyCompany MyState" appears in the document,
so simply replacing "MyCompany" with "MyCompany MyState"
will not work in all cases. Another wrinkle is that
sometimes "MyCompany" is followed immediately by a
punctuation mark, so I can't search for "MyCompany " (with
the added space).
Another difficulty I have encountered with wildcard
searches is after I have found, for instance, "MyCompany
is growing" I want to replace it with "MyCompany MyState
is growing", but when I have managed to contrive searches
that find "My Company (something other than "MyState")", I
can't avoid replacing the part that follows "MyCompany".
Backslashes seem to enter into solving this, but I can't
make out how they owrk in the Replace part of the function.
I realize I could do a simpler search, and just skip some
replacements as needed, but I have a project that involves
some very large documents that will require extensive
editing, so I would like to make use of Replace if it has
the capabilities I need.
.
 
G

Graham Mayor

I have re-written the wildcard article that is on the MVPS web site for my
own site. The layout is different and the text changed to try and make it
clearer - see http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Thanks for taking the time to reply. Yes, I could do
that. However, with a lot of editing to do I am trying to
learn how to make the most of wildcard searches. My
question is not so much about the situation I outlined as
it is about using the feature effectively enough that I
don't have to review every replacement in a long document.
-----Original Message-----
Could you replace all instances of "MyCompany" with "My
Company MyState", and then replace all instances
of "MyState MyState" with "MyState"?
Bruce said:
I would like to find instances of "MyCompany" and replace
them with "MyCompany MyState". I have already downloaded
an article by Graham Mayor (from the MVP site, I think),
so if your reply is to refer me to that article, I already
have it, thank you. My general approach has been to
search for "MyCompany (anything other than "MyState")" and
replace it with "MyCompany MyState", but between [], [!],
<>, etc. I have managed to generate quite a variety of
worthless error messages, but have made no progress toward
the desired result.
In some cases "MyCompany MyState" appears in the document,
so simply replacing "MyCompany" with "MyCompany MyState"
will not work in all cases. Another wrinkle is that
sometimes "MyCompany" is followed immediately by a
punctuation mark, so I can't search for "MyCompany " (with
the added space).
Another difficulty I have encountered with wildcard
searches is after I have found, for instance, "MyCompany
is growing" I want to replace it with "MyCompany MyState
is growing", but when I have managed to contrive searches
that find "My Company (something other than "MyState")", I
can't avoid replacing the part that follows "MyCompany".
Backslashes seem to enter into solving this, but I can't
make out how they owrk in the Replace part of the function.
I realize I could do a simpler search, and just skip some
replacements as needed, but I have a project that involves
some very large documents that will require extensive
editing, so I would like to make use of Replace if it has
the capabilities I need.
.
 
B

Bruce

The new article clears up some things that were questions
from the first article. One thing that is still not quite
clear is the use of a backslash in the Replace string. As
nearly as I can tell, \1 in the Replace string is intended
to represent the first instance of a pair of parentheses
enclosing something or other.
I have concluded that I cannot do what I want to in one
pass. I will need to break the search into segments. I
had intended to replace "MyCompany followed by anything
other than SPACE MyState" with "MyCompany MyState". It
seems that cannot be done. The space is a problem,
apparently. So I tried Find: MyCompany ([!M]), and
Replace: MyCompany MyState \1. However, when the found
text was "MyCompany Grows", the replacement was something
like "MyComGpany Mystate rows". If this is a feature I
cannot imagine its function. Searching for something
other than a specific word (maybe something like [!
<MyState>] does not work either. I think I have to just
accept that I will need to do the Replace in several
stages. The process clearly has some significant
limitations and quirks.
Thanks for maintaining the article about wildcards. Word
Help has buried the information somewhere, and it is
incomplete and confusing even when it can be found. It
really is too bad that so much of the functionality of
Word is suppressed by a simplistic interface that tends to
bury Word's best features.
-----Original Message-----
I have re-written the wildcard article that is on the MVPS web site for my
own site. The layout is different and the text changed to try and make it
clearer - see http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Thanks for taking the time to reply. Yes, I could do
that. However, with a lot of editing to do I am trying to
learn how to make the most of wildcard searches. My
question is not so much about the situation I outlined as
it is about using the feature effectively enough that I
don't have to review every replacement in a long document.
-----Original Message-----
Could you replace all instances of "MyCompany" with "My
Company MyState", and then replace all instances
of "MyState MyState" with "MyState"?
:

I would like to find instances of "MyCompany" and replace
them with "MyCompany MyState". I have already downloaded
an article by Graham Mayor (from the MVP site, I think),
so if your reply is to refer me to that article, I already
have it, thank you. My general approach has been to
search for "MyCompany (anything other than "MyState")" and
replace it with "MyCompany MyState", but between [], [!],
<>, etc. I have managed to generate quite a variety of
worthless error messages, but have made no progress toward
the desired result.
In some cases "MyCompany MyState" appears in the document,
so simply replacing "MyCompany" with "MyCompany MyState"
will not work in all cases. Another wrinkle is that
sometimes "MyCompany" is followed immediately by a
punctuation mark, so I can't search for "MyCompany " (with
the added space).
Another difficulty I have encountered with wildcard
searches is after I have found, for instance, "MyCompany
is growing" I want to replace it with "MyCompany MyState
is growing", but when I have managed to contrive searches
that find "My Company (something other than "MyState")", I
can't avoid replacing the part that follows "MyCompany".
Backslashes seem to enter into solving this, but I can't
make out how they owrk in the Replace part of the function.
I realize I could do a simpler search, and just skip some
replacements as needed, but I have a project that involves
some very large documents that will require extensive
editing, so I would like to make use of Replace if it has
the capabilities I need.


.


.
 
G

Graham Mayor

Try
(MyCompany )([!M])
replace with
\1MyState \2

The slashed numbers replace the bracketed texts in the order they appear in
the search string.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


The new article clears up some things that were questions
from the first article. One thing that is still not quite
clear is the use of a backslash in the Replace string. As
nearly as I can tell, \1 in the Replace string is intended
to represent the first instance of a pair of parentheses
enclosing something or other.
I have concluded that I cannot do what I want to in one
pass. I will need to break the search into segments. I
had intended to replace "MyCompany followed by anything
other than SPACE MyState" with "MyCompany MyState". It
seems that cannot be done. The space is a problem,
apparently. So I tried Find: MyCompany ([!M]), and
Replace: MyCompany MyState \1. However, when the found
text was "MyCompany Grows", the replacement was something
like "MyComGpany Mystate rows". If this is a feature I
cannot imagine its function. Searching for something
other than a specific word (maybe something like [!
<MyState>] does not work either. I think I have to just
accept that I will need to do the Replace in several
stages. The process clearly has some significant
limitations and quirks.
Thanks for maintaining the article about wildcards. Word
Help has buried the information somewhere, and it is
incomplete and confusing even when it can be found. It
really is too bad that so much of the functionality of
Word is suppressed by a simplistic interface that tends to
bury Word's best features.
-----Original Message-----
I have re-written the wildcard article that is on the MVPS web site for my
own site. The layout is different and the text changed to try and
make it clearer - see http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Thanks for taking the time to reply. Yes, I could do
that. However, with a lot of editing to do I am trying to
learn how to make the most of wildcard searches. My
question is not so much about the situation I outlined as
it is about using the feature effectively enough that I
don't have to review every replacement in a long document.
-----Original Message-----
Could you replace all instances of "MyCompany" with "My
Company MyState", and then replace all instances
of "MyState MyState" with "MyState"?

:

I would like to find instances of "MyCompany" and replace
them with "MyCompany MyState". I have already downloaded
an article by Graham Mayor (from the MVP site, I think),
so if your reply is to refer me to that article, I already
have it, thank you. My general approach has been to
search for "MyCompany (anything other than "MyState")" and
replace it with "MyCompany MyState", but between [], [!],
<>, etc. I have managed to generate quite a variety of
worthless error messages, but have made no progress toward
the desired result.
In some cases "MyCompany MyState" appears in the document,
so simply replacing "MyCompany" with "MyCompany MyState"
will not work in all cases. Another wrinkle is that
sometimes "MyCompany" is followed immediately by a
punctuation mark, so I can't search for "MyCompany " (with
the added space).
Another difficulty I have encountered with wildcard
searches is after I have found, for
instance, "MyCompany
is growing" I want to replace it with "MyCompany MyState
is growing", but when I have managed to contrive searches
that find "My Company (something other
than "MyState")", I
can't avoid replacing the part that
follows "MyCompany".
Backslashes seem to enter into solving this, but I can't
make out how they owrk in the Replace part of the function.
I realize I could do a simpler search, and just skip some
replacements as needed, but I have a project that involves
some very large documents that will require extensive
editing, so I would like to make use of Replace if it has
the capabilities I need.


.


.
 

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