Regular Expression Incrementing Counters
Regular Expression Counter operations allow you to revise a sequence of numbers in one or more files. The program can also insert sequential numbers in strings where no numbers exist originally. Counter operations use the ?[0-9], +[0-9], or *[0-9] regular expression search operators and the %n>user defined starting value> or %n<user defined starting value< regular expression replacement operators. Counter increment +/-1 from the starting value specified. If no value is supplied, as in %n>> or %n<<, then incrementing begins with a value of +/- 1 from the value found by your *[0-9] expression. For example, if the value found by the *[0-9] search expression is 10, %n>> begins at 11.
The %n>user defined starting value> and %n<user defined starting value< replacement operators respect the number of digit places supplied. For example, the expression %1>1> begins incrementing with 2. The expression %1>000> begins incrementing with 001.
Negative values can be used for the starting value. For example, %1>-5> replaces with -4, -3, -2, -1, 0, à .
Arithmetic calculations are not available for counter operations. The?[0-9], +[0-9], or *[0-9] operators do not perform numeric evaluations. These are ordinary [ ] range operators that search for the characters 0 to 9. Keep this in mind if you are searching for number strings along with $ or . characters. A search for +[\$.0-9] finds '$53.00' but the program does not interpret this as 'fifty-three dollars'. Counters will not work in this case. The - (minus) character is an exception. +[\-0-9] is OK for counter operations involving search hits such as '-53'. If you need to do searching-counters for strings like '$53.00', consider a search string such as \$+[0-9].+[0-9] and (perhaps) a replace such as $%1>>.%2.
Incrementing counter operations may be combined with other regular expression search & replace operators. For example, a search expression such as (file|variable)*[0-9] with a counter replacement expression such as %1%2>100> is allowed.
If the search uses multiple?[0-9], +[0-9], or *[0-9] search terms the replacement can use different counter terms. Example: Search - cat*[0-9] dog*[0-9], Replace - cat%1>> dog%2>100>. Please note that the replacement term should maintain the positions of the %n terms in the search string. Do not, for example, use cat%2>> dog%1>100> in a replace string.
By default %n>user defined starting value> & %n<user defined starting value< reset with each file if your search spans multiple files. See the "Multiple Files - Default Behavior" example below.
A special registry switch can be used to cause %n>user defined starting value> & %n<user defined starting value< replacements to sequence across files. The special configuration utility on the Search & Replace home page can also be used to activate the "Count Across Files" switch. The switch can also be used in manually created scripts.
See the "Multiple Files - Sequence Across Files" below for examples of the behavior when the program sequences across files. The order in which the files are processed is determined by the sort order of files in the Search Results list. This can be adjusted via the 'Sort search results by' field in Options-Search. For example, given FILE1.TXT and FILE2.TXT, a sort order of File Name-Ascending causes FILE1.TXT to begin the sequence. A sort order of File Name-Descending causes FILE2.TXT to begin the sequence.
Regular Expression Counter Examples |
|
Initial Contents: |
Windows 98 will be released in 5 days. |
Initial Contents: |
file.htm, file.htm, ffillee.htm |
Initial Contents: |
Var22 Var20 Var86 Var30 |
Initial Contents: |
Var22 Var20 Var86 Var30 |
Initial Contents: |
VarA101 VarB12 VarC0 VarA102 VarB45 |
Regular Expression Counter
Example |
|
File1 Contents: |
cat01 dog01 |
Regular Expression Counter
Example |
|
File1 Contents: Sort Order: Sort Order: |
cat01 dog01 File Name-Ascending File Name-Descending |