Regular Expression Replacement Operators
Replacement Operators Index | |
Basic Operators |
Special Operators |
Related Topics | |
Regular Expression Search Operators |
Notes on Replacement Expressions:
The operatorsÆ matches can be replaced with nothing (removed). The case of the text matched can be changed. Matches can also be left intact. All operators may match some strings and therefore all should be accounted for in the replace expression.
The following characters have special meaning in regular expression replace terms. If you wish to use the literal of one of these characters, preface them with the \ character.
% \ < >
For example, the % character normally denotes the %n basic replacement operator. If you want to use a literal % character in your replace string, denote that as \%. See Regular Expression Literals for more information.
Up to 31 parameters may be used at once by referring to those over number nine by moving up the ASCII table, e.g., 123456789:;<=>?@ABCDEFGHIJKLMN. A complete list is present in the %n table. Dealing with a large number of %n terms can make for a very complex replacement term. Our Regular Expression Wizard may be helpful - it breaks out the number equivalents in the search term. Also consider using multiple steps to tackle your operation, perhaps via a multi-step script search-replace. In some cases several passes with simpler expressions is faster than one pass through your files with a highly complex expression.
To view the result of all replace operations, turn on the "Prompt on All" radio button under Replace Options.
You may wish to increase the "Maximum Regular Expression Size" under Search Options if you have a regular expression search that involves Binary Characters and/or is very complex.
Please See Word Documents Notes for important information on search & replaces in non-text files such as Word documents, Word Perfect documents, spreadsheets, etc.
Regular Expression Replacement Operators | ||
%n |
Basic Replacement Operator: The replacement operators use a %n convention, where n corresponds to a component in the regular expression search string. For example, %1 refers to the first expression in the search string, %2 refers to the second, and so on. The %n parameters may be used several times, omitted, or used in any order. Up to 31 parameters may be used at once by referring to those over number %9 moving up the ASCII table, e.g., 123456789:;<=>?@ABCDEFGHIJKLM. See %n table for more information and examples. Some examples of %n usage are: | |
|
Given the series: |
<a href="http://wait.com">s1</a> |
|
Given the series: |
<BR> |
|
Given the series: |
#include [stdafx.h] |
< |
Lower Case Operator: This is to be used in conjunction with %n, where %n< replaces the original matched expression with the lower case version. For example, | |
|
Given: |
MAKE THIS ALL LOWER CASE |
> |
Upper Case Operator: This is to be used in conjunction with %n: For example, %1> replaces the original first matched expression with the upper case version. For example, | |
|
Given the series: |
All words beginning with letter w. |
%n>> |
Plain Counter Operator: This is a special case of the %n>#> and %n<#< operators below, where no starting value is defined by the user. When used in conjunction with a numeric regular expression search such as *[0-9], %n>> and %n<< begin incrementing up or down with a value of +/-1 from the value of the first number found by *[0-9]. For example, | |
|
Given the series: |
page5.htm, page2.htm, page4.htm |
|
See Counter Operators for more information & examples. |
%n>#> |
Start Value Counter Operator: An extension of the above, this operator allows you to specify a starting value for an incrementing replacement counter. %n>starting value> and %n<starting value< begin counting up or down with a value of +/-1 from the starting value you supply. This counter operator respects the number of digit places you supply. To begin incrementing upward with a value of 1, use the expression %n>0>. The expression %n>000> would begin replacements with a value of 001. Another example is: | |
|
Given the series: |
Var19, Var82, Var8 |
|
See Counter Operators for more information & examples. |
%n<%num format(Math Op)> |
Number Operation: This is a Number Parsing & Math Operation. These operations take search terms that return strings of numbers and handle them internally as integer or decimal numbers (depending on your specifications). Arithmetic operations are optional. If present, they are specified in ( ) before the closing > character. The format rules are much too complex to summarize here so please see Number Operations for more details. | |
|
Given: |
page5.htm, page2.htm, page18.htm |
Regular Expression Replacements - Special Characters (Literals) | |
% \ < > |
If you wish to replace any of these characters, they must be preceded by the \ character to be interpreted as a literal in a replacement. |