Described below is a general introduction about the Expression Evaluator, some specific notes, and some basic examples.
Introduction:
Expression Evaluator Field
The "Expression Evaluator" is the "Process file when expression is non-zero" field in the Advanced Script Settings dialog. The expression in this field determines which files among those meeting the file mask, path, and filter criteria are ultimately processed by your script. If the result of the expression is 1 for a file, that file will be processed further. Under the default OR expression, all files meeting the file mask, path, and filter criteria are processed because the value of the expression would be 1 for each file - If a search string makes a hit, that search (or replace) will occur. Other combinations of operators and variables in the expression would allow you to process only certain files within the domain of possible files according to your file masks, path, & filters.
The variables E1, E2, ... En reference the search/replace string pairs in the script. A script with 3 strings would have E1, E2, & E3 available.
The valid operators are: AND OR NOT < > <= >= >+ = != + - * /
The default expression is an OR statement, e.g., E1 OR E2 OR E3
Numeric values may be used in conjunction with variables to denote the number of replacement opportunities in a file. For example, the expression
E1 AND (E2 = 4)
would process only those files where the first search & replace pair could occur one (or more) times and the second search & replace pair could occur exactly 4 times.
Notes on the Expression Evaluator:
Advanced Script Settings are intended for scripts run via batch files using the command line switches for Search and Replace. They are designed to be used with replacement prompting turned off. Be sure to read the help section on Advanced Expressions and Replacement Operations for information about the behavior of replacement prompts when a complex expression is in effect and advice on debugging your expressions.
Unary versions of the + and - operators must be enclosed in parentheses, e.g., (-1).
You can compare one string
to another, e.g.,
E1 AND NOT(E2 != (E3)))
E1 AND NOT(E2=1 or (E3 != (-1)))
E1 and (E1 >= 1) are equivalent. Conversely, NOT E1 and (E1 = 0) are equivalent.
Operators are parsed in
the following order:
1) (
2) * /
3) + -
4) = != > >= < <=
5) NOT
6) AND
7) OR
Search and Replace checks the expression syntax for unbalanced parentheses, invalid variables, and missing or incorrect operators. Upon errors involving invalid variables, the program will change the expression to an OR statement matching the number of search strings in the script. For example, say you create a script manually that contains 2 search strings and the expression E1 AND (E2 != E3). When the script is loaded into Search and Replace, the program will notify you of the error involving variable E3 (it should not be present in a 2 string script) and the expression will be changed to E1 OR E2.
By using the "Move Up" and "Move Down" buttons on the main Script Editor dialog to rearrange the search & replace strings, the strings associated with the En variables in the Expression Evaluator will change. Depending on your expression, rearranging strings may be more convenient than rewriting the expression itself.
Some Basic Expression Evaluator Examples:
Note: These examples assume that Replacement Prompts are disabled OR no "Skip" replacements are allowed if Replace Prompts are turned on. See Advanced Expressions and Replacement Operations for more information about the possible influence of "Skip(s)" on expressions involving numeric values.
FILE CONTENTS |
||
File 1 |
File 2 |
File 3 |
JILL |
JACK |
JILL |
Script Search Strings: E1 = JILL |
||
Expression Evaluator: E2 AND E4 |
||
Files That Would Be Processed: FILE 2 |
FILE CONTENTS |
||
File 1 |
File 2 |
File 3 |
JILL |
JACK |
JILL |
Script Search Strings: E1 = JILL |
||
Expression Evaluator: E1 AND E4 |
||
Files That Would Be Processed: None |
FILE CONTENTS |
||
File 1 |
File 2 |
File 3 |
12/18/94 |
12/01/95 |
12/19/95 |
Script Search Strings: (Note: E2 is a Regular Expression) E1 = 12 |
||
Expression Evaluator: E1 AND E2 AND ((E3 >= 2 OR E4) |
||
Files That Would Be Processed: FILE2 FILE3 |