Can seach queries be used with Replace and Batch Replace?

General discussions about Advanced Find and Replace
Post Reply
SM

Can seach queries be used with Replace and Batch Replace?

Post by SM » Mon Jan 31, 2005 5:32 pm

Hi - I need to run a simple query. Is this only available to Find, or can it be done in Replace or Batch?

Can't see how to do it.

Thanks
SM

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Mon Jan 31, 2005 5:32 pm

In Replace and Batch Replace you have "Just Find" option.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Guest

Re:Can seach queries be used with Replace and Batch Replace?

Post by Guest » Mon Jan 31, 2005 5:32 pm

Roman wrote:In Replace and Batch Replace you have "Just Find" option.


Thanks, but I think I must make my question clearer:

Why is not the Search Query option in Find available in the Replace options? It would be most useful. (Or should I use regular expressions?)

E.g. if I want to replace all instances of string RD(xyz) with WRD(xyz) not where WRD(xyz) already exists, I suppose an expression will do it?

SM

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Mon Jan 31, 2005 5:32 pm

Try to ask more specific questions.

Search Query in Find tab is intended for search engine. It's a simple
query language with using "" - + which is supposed to use for quick search
through many files.

Replace tab is also some kind of simplification with its Insert
Before, Insert after and so on.
The real replace "power" may be only achieved by using regular
expressions.

But lets talk about your concrete example.

Suppose that you want to:
1. replace all literal strings RD(xyz) by WRD(xyz).
2. avoid replacing WRD(xyz) by WRD(xyz) (in opposite case it gives
WWRD(xyz)).

So for this task you may use the both:
1. Replace with "Replace with" operation.

or

2. Batch replace.

Put RD(xyz) in "search for" and WRD(xyz) in "replace by".

But OK the key is to switch on "Whole words only" option.

So lets take the sample text:
Print; RD(xyz); Output;
WRD(xyz); Quit;

In the first line RD(xyz) is surrounded by space from the left and ;
from the right. These chars are not in a..z A..Z 0..9 group which
means that they are considered as "space" (or "nonalphanumeric") chars.
So in the first line RD(xyz) is considered as a whole word.
But in the second line we find W before RD. Which means that in the
second line RD(xyz) is not a whole word.

So for this sample it's quite easy to use Whole Words Only option.
But it can also be done by using regular expressions on Batch replace
tab.
Switch on "Use regular expressions".
Put "Search for":
(\W)RD\(xyz\)(\W)

"Replace with":
$1WRD(xyz)$2

So \W means nonalphanumeric char.
We use \( because to avoid ( as reserved char in "Search for" part
(but not in "Replace with".
$1 and $2 - in order to copy taken by () in (\W) nonalphanumeric
chars.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest