Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

using wildcards to do A replace in word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Horace - 05 Oct 2007 06:06 GMT
I am familiar with the use of wild cards from UNIX. I have no problems
finding what I need.

To find MAJOR|v- I put in MAJOR|?- and it finds the stings I need. But when
I try to do a replace with MAJOR|\1x I get an error message. The replace
function gives me the error "The Replace with text contains a group number
which is out of range."  I need advice on how to properly use the variable in
the replace that represents the wildcard in the find.
Graham Mayor - 05 Oct 2007 06:26 GMT
See http://www.gmayor.com/replace_using_wildcards.htm

In this instance you would search for
MAJOR|(?)
replace with
MAJOR|\1x

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I am familiar with the use of wild cards from UNIX. I have no problems
> finding what I need.
[quoted text clipped - 5 lines]
> to properly use the variable in the replace that represents the
> wildcard in the find.
Klaus Linke - 05 Oct 2007 06:26 GMT
>I am familiar with the use of wild cards from UNIX. I have no problems
> finding what I need.
[quoted text clipped - 6 lines]
> in
> the replace that represents the wildcard in the find.

UNIX regex implementations use other wildcards than Word (and other
wildcards than other UNIX regex implementations <g>).

In Word, \1 matches the first "group", that is, the first expression you put
in (brackets).
If you want to find the literal "\1", use \\1 in "Find what".
You get the error message, because there isn't a group \1 in your search.

Regards,
Klaus
Klaus Linke - 05 Oct 2007 06:40 GMT
> If you want to find the literal "\1", use \\1 in "Find what".

Sorry, I noticed (from Graham's reply) you use the backslash in "Replace
with".
I'd have thought \\ would insert a backslash in "Replace with" too, but it
seems it does not.
You could use ^92 though (using the decimal ASCII code of the backslash).

The wildcards \1, \2 ... are used most often in "Replace with", but can
actually be useful in "Find what", too.
Say ([st])?\1 would match "tot" and "sas", but not "sat".

Klaus
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.