using wildcards to do A replace in word

H

Horace

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.
 
K

Klaus Linke

Horace said:
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.

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
 
K

Klaus Linke

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
 

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