Scripts – Iteration Operator

Script Loop=

Search and Replace v3.2+ has a special script operator, Script Loop=x, to permit a script to be repeated x number of times.

This operator is useful for situations where a search/replace string might not make all possible replacements on the first pass. This can happen, for example, when a * or *[] search operator in your overall regular expression search term spans text that includes a string component that you wish to have replacements done on. This can also happen if a replacement somehow impacts the next instance of a string that would be found by the search term.

Non-Regular Expression search/replaces would likely not be affected in this way.

The value can be larger than necessary. If no more search hits are found the program will stop the iterations.

Usage:

Script Loop=x

where x = the number of times to repeat the script. Search and Replace does not have an internal limit for the maximum value. Use a value of -1 to cause the script to repeat indefinitely (not recommended). Press the ESC key to abort a running script.

The Script Loop= setting must be added manually, via an external text editor.

This switch must be the last item in the [Options] section of the script.

Be sure to reload the script into Search and Replace if are using that same script in Search and Replace and made a manual edit with an external editor.

See Scripts – Format of Script files for more detail. Here is a small sample script:

[Script for Search and Replace]
[Options]
Script Loop=5
[Search /ix]
^\r\n\r\n\r\n
[Replace]
\r\n\r\n
[End of Search and Replace Script]

Iteration Operator