Wildcard search finds okay, but replaces wrong??

E

Ed

Using Ctrl+H, with "Use Wildcards" checked, I am searching for
(^t^t^t)(i.)([ ]{1,2})
I want to replace with
(^t^t)([^40]1[^41])([ ])
(The last time I tried a wildcard search, I had trouble with [\(] and [\)],
and I substituted ^40 and ^41 and it worked fine.)

The Find part works great. The Replace, though, is actually inserting the
"(^t^t)([^40]1[^41])([ ])", rather than two tabs, (1), and two spaces!!
Why??

--
Ed
Chief Chef,
Kludge Code Cafe
"Spaghetti Is Our Specialty!"
'
 
V

verticalfont

You don't need any of the parens. You can get rid of them in the find
and the replace. They are for replacing variable found targets, which
you are not doing.

You can use regular parens in the replace and you do not need brackets
there.

Just to fix your immediate problem

^t^t^ti. {1,2} as the find what and
^t^t(1) as the replace with will work fine.
 
E

Ed

Thanks. It does work. But a question: then does "Use Wildcards" only
apply to the Find text? Why isn't it throwing an error on the parentheses
in the Replace With text? I would have thought they would need to be
escaped or replaced with character equivalents.

Ed

You don't need any of the parens. You can get rid of them in the find
and the replace. They are for replacing variable found targets, which
you are not doing.

You can use regular parens in the replace and you do not need brackets
there.

Just to fix your immediate problem

^t^t^ti. {1,2} as the find what and
^t^t(1) as the replace with will work fine.

Using Ctrl+H, with "Use Wildcards" checked, I am searching for
(^t^t^t)(i.)([ ]{1,2})
I want to replace with
(^t^t)([^40]1[^41])([ ])
(The last time I tried a wildcard search, I had trouble with [\(] and
[\)],
and I substituted ^40 and ^41 and it worked fine.)

The Find part works great. The Replace, though, is actually inserting
the
"(^t^t)([^40]1[^41])([ ])", rather than two tabs, (1), and two spaces!!
Why??

--
Ed
Chief Chef,
Kludge Code Cafe
"Spaghetti Is Our Specialty!"
'
 
K

Klaus Linke

Ed said:
Thanks. It does work. But a question: then does "Use Wildcards" only
apply to the Find text? Why isn't it throwing an error on the parentheses
in the Replace With text? I would have thought they would need to be
escaped or replaced with character equivalents.


Hi Ed,

Apart from the backslash \ and the caret ^, there aren't any characters with
special meaning in "Replace with", so there is no need for braces (or any of
the other "Find what" wildcards) to be escaped.

The only wildcards in "Replace with" are \1, \2, ..., and the jokers like
^&, ^c, ...

Say in your replacement, you could have re-inserted the leading two tabs:
Find what: (^t^t)^ti.[ ]{1,2}
Replace with: \1(1)^32

\1 here re-inserts the content of the (first) brace (^t^t).

You could have typed a space instead of ^32 ...
I just used ^32 so it because a space would have been invisible in this
post, and to demonstrate a use of the ^caret in "Replace with".

Regards,
Klaus
 
E

Ed

Thank you, Klaus. So the answer to:is apparently Yes? I'll have to remember this - it will make things much
easier.

Just to check - this is also true in VBA using the Find object? Originally
this was going to be part of a macro with a number variable that would
increment as it looped (but I couldn't find a way to get the number into a
small Roman numeral format - I have a post in the VBA NG asking about this
now).

Ed


Klaus Linke said:
Ed said:
Thanks. It does work. But a question: then does "Use Wildcards" only
apply to the Find text? Why isn't it throwing an error on the
parentheses in the Replace With text? I would have thought they would
need to be escaped or replaced with character equivalents.


Hi Ed,

Apart from the backslash \ and the caret ^, there aren't any characters
with special meaning in "Replace with", so there is no need for braces (or
any of the other "Find what" wildcards) to be escaped.

The only wildcards in "Replace with" are \1, \2, ..., and the jokers like
^&, ^c, ...

Say in your replacement, you could have re-inserted the leading two tabs:
Find what: (^t^t)^ti.[ ]{1,2}
Replace with: \1(1)^32

\1 here re-inserts the content of the (first) brace (^t^t).

You could have typed a space instead of ^32 ...
I just used ^32 so it because a space would have been invisible in this
post, and to demonstrate a use of the ^caret in "Replace with".

Regards,
Klaus
 
K

Klaus Linke

Yes in principle. Only, in the VBA editor you can't use Unicode characters
(code > 255), and have to "escape" quote marks with another quote mark, or
use ChrW(34).

Klaus


Ed said:
Thank you, Klaus. So the answer to:is apparently Yes? I'll have to remember this - it will make things much
easier.

Just to check - this is also true in VBA using the Find object?
Originally this was going to be part of a macro with a number variable
that would increment as it looped (but I couldn't find a way to get the
number into a small Roman numeral format - I have a post in the VBA NG
asking about this now).

Ed


Klaus Linke said:
Ed said:
Thanks. It does work. But a question: then does "Use Wildcards" only
apply to the Find text? Why isn't it throwing an error on the
parentheses in the Replace With text? I would have thought they would
need to be escaped or replaced with character equivalents.


Hi Ed,

Apart from the backslash \ and the caret ^, there aren't any characters
with special meaning in "Replace with", so there is no need for braces
(or any of the other "Find what" wildcards) to be escaped.

The only wildcards in "Replace with" are \1, \2, ..., and the jokers like
^&, ^c, ...

Say in your replacement, you could have re-inserted the leading two tabs:
Find what: (^t^t)^ti.[ ]{1,2}
Replace with: \1(1)^32

\1 here re-inserts the content of the (first) brace (^t^t).

You could have typed a space instead of ^32 ...
I just used ^32 so it because a space would have been invisible in this
post, and to demonstrate a use of the ^caret in "Replace with".

Regards,
Klaus
 
E

Ed

Thanks for all your help, Klaus. I appreciate it.
Ed

Klaus Linke said:
Yes in principle. Only, in the VBA editor you can't use Unicode characters
(code > 255), and have to "escape" quote marks with another quote mark, or
use ChrW(34).

Klaus


Ed said:
Thank you, Klaus. So the answer to:
But a question: then does "Use Wildcards" only apply to the Find text?
is apparently Yes? I'll have to remember this - it will make things much
easier.

Just to check - this is also true in VBA using the Find object?
Originally this was going to be part of a macro with a number variable
that would increment as it looped (but I couldn't find a way to get the
number into a small Roman numeral format - I have a post in the VBA NG
asking about this now).

Ed


Klaus Linke said:
Thanks. It does work. But a question: then does "Use Wildcards" only
apply to the Find text? Why isn't it throwing an error on the
parentheses in the Replace With text? I would have thought they would
need to be escaped or replaced with character equivalents.


Hi Ed,

Apart from the backslash \ and the caret ^, there aren't any characters
with special meaning in "Replace with", so there is no need for braces
(or any of the other "Find what" wildcards) to be escaped.

The only wildcards in "Replace with" are \1, \2, ..., and the jokers
like ^&, ^c, ...

Say in your replacement, you could have re-inserted the leading two
tabs:
Find what: (^t^t)^ti.[ ]{1,2}
Replace with: \1(1)^32

\1 here re-inserts the content of the (first) brace (^t^t).

You could have typed a space instead of ^32 ...
I just used ^32 so it because a space would have been invisible in this
post, and to demonstrate a use of the ^caret in "Replace with".

Regards,
Klaus
 
K

Klaus Linke

The easiest way to create the Find code is usually with the macro recorder.

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