Match Placeholders

Match placeholders can be used to insert search matches or match counts in the search text or replacement text.

Placeholder Meaning and Examples Availability
%LINE% The line the search match was found on. Replacement text.
%LINEN% The number of the line the match was found on. Replacement text.
%MATCH% The search match. Replacement text.
%MATCHN% The number of the search match. Counts the number of search matches already found. %MATCHN% will be one for the first replacement. Replacement text.
%GROUP1%, %GROUP2%, etc. %GROUP1% is a backreference to a capturing group, equivalent to \1 in a regular expression or \1 or $1 in the replacement text. The advantage of %GROUP1% is that you can use the padding and case conversion specifiers listed below. Search term and replacement text, but only when using regular expressions with numbered capturing groups.
%GROUPNAME%, %GROUPanothername%, etc. %GROUPNAME% is a backreference to a named capturing group, equivalent to \k'NAME' or (?P=NAME) in a regular expression and to ${NAME} or \g<NAME> in the replacement text. The NAME part of the placeholder is case sensitive. The advantage of %GROUPNAME% is that you can use the padding and case conversion specifiers listed below. Search term and replacement text, but only when using regular expressions with named capturing groups.

Padding

You can add additional specifiers to all of the above placeholders. You can pad the placeholder’s value to a certain length, and control the casing of any letters in its value. The specifiers must appear before the second % sign in the placeholder, separated from the placeholder’s name with a colon. E.g. %MATCH:6L% inserts the match padded with spaces at the left to a length of 6 characters. You can add both padding and case placeholders. %MATCH:U:6L% inserts the padded match converted to uppercase.

Padding specifiers start with a number indicating the length, followed by a letter indicating the padding style. The length is the number of characters the placeholder should insert into the regular expression or replacement text. If the length of the placeholder’s value exceeds the requested length, it will be inserted unchanged. It won’t be truncated to fit the length. If the value is shorter, it will be padded according to the padding style you specified.

The L or “left” padding style puts spaces before the placeholder’s value. This style is useful for padding numbers or currency values to line them up in columns. The R or “right” padding style puts spaces after the placeholder’s value. This style is useful for padding words or text to line them up in columns. The C or “center” padding style puts the same number of spaces before and after the placeholder’s value. If an odd number of spaces is needed for padding, one more space will be placed before the value than after it.

The Z or “zero” padding style puts zeros before the placeholder’s value. This style is useful for padding sequence numbers.

Case Conversion

Case conversion specifiers consist of a letter only. The specifier letters are case insensitive. Both “U” and “u” convert the placeholder’s value to uppercase. L converts it to lowercase, I to initial caps (first letter in each word capitalized) and F to first cap only (first character in the value capitalized). E.g. %MATCH:I% inserts the match formatted as a title.

Arithmetic

Arithmetic specifiers perform basic arithmetic on the placeholder’s value. This works with any placeholder that, at least prior to padding, represents an integer number. If the placeholder does not represent a number, the arithmetic specifiers are ignored. For placeholders like %MATCH% that can sometimes be numeric and other times not, the arithmetic specifiers are used whenever the placeholder happens to represent an integer.

An arithmetic specifier consists of one or more operator and integer pairs. The operator can be +, -, *, or / to signify addition, subtraction, multiplication, or integer division. It must be followed by a positive integer. Arithmetic specifiers are evaluated strictly from left to right. When %MATCHN% evaluates to 2, %MATCHN:+1*2% evaluates to 6 because 2+1=3 and 3*2=6. Multiplication and division do not take precedence over addition and subtraction. Integer division drops the fractional part of the division’s result, so %MATCHN:/3% evaluates to 0 for the first two matches.

See Also

Search menu
Search|Prepare to Search
Path Placeholders