Match Placeholders

Match placeholders can be used to insert search matches or match counts in the search text or replacement text. For this to work, the option "Expand match placeholders and path placeholders" must have been enabled in the action & results preferences. You can easily insert match placeholders by right-clicking on an edit box on the Action panel and selecting Insert Match Placeholder in the placeholders menu.

Placeholder Meaning and Examples Availability
%ACTIONDATE% Date on which PowerGREP started executing the action. Everywhere
%ACTIONTIME% Time of the day (hours, minutes, and seconds) on which PowerGREP started executing the action. Everywhere
%ACTIONDAY% Day of the month on which PowerGREP started executing the action. Everywhere
%ACTIONMONTH% Number of the month on which PowerGREP started executing the action. Everywhere
%ACTIONYEAR% Year during which PowerGREP started executing the action. Everywhere
%ACTIONHOUR12% Hour based on a 12-hour clock on which PowerGREP started executing the action. Everywhere
%ACTIONHOUR24% Hour based on a 24-hour clock on which PowerGREP started executing the action. Everywhere
%ACTIONAMPM% Replaced with AM or PM depending on whether PowerGREP started executing the action before noon or after noon. Everywhere
%FILEN% and %FILENZ% The number of the file being searched through. Counts all files that are searched through, including those without matches. Files are numbered in no particular order if the Action Preferences are set to process files in multiple threads. Files are numbered in alphabetical order if the Action Preferences are set to use only a single thread. %FILEN% starts counting at one, and %FILENZ% at zero. Everywhere
%FILENA% The sequential letter of the file being searched through. The first file is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. Everywhere
%FILEDATE% Date on which the file currently being processed by the action was last modified. Everywhere
%FILETIME% Time of the day (hours, minutes, and seconds) on which the file currently being processed by the action was last modified. Everywhere
%FILETIME% Time of the day (hours, minutes, and seconds) on which the file currently being processed by the action was last modified. Everywhere
%FILEDAY% Day of the month on which the file currently being processed by the action was last modified. Everywhere
%FILEMONTH% Number of the month on which the file currently being processed by the action was last modified. Everywhere
%FILEYEAR% Year during which the file currently being processed by the action was last modified. Everywhere
%FILEHOUR12% Hour based on a 12-hour clock on which the file currently being processed by the action was last modified. Everywhere
%FILEHOUR24% Hour based on a 24-hour clock on which the file currently being processed by the action was last modified. Everywhere
%FILEAMPM% Replaced with AM or PM depending on whether the file currently being processed by the action was last modified before noon or after noon. Everywhere
%FILESIZE% Size in bytes of the file currently being processed by the action (prior to any changes made by the action). Everywhere
%FILESIZEKB% Size in kilobytes (1,000 bytes) of the file currently being processed by the action (prior to any changes made by the action). Everywhere
%FILESIZEKIB% Size in kibibytes (1,024 bytes) of the file currently being processed by the action (prior to any changes made by the action). Everywhere
%FILESIZEMB% Size in megabytes (1,000,000 bytes) of the file currently being processed by the action (prior to any changes made by the action). Everywhere
%FILESIZEMIB% Size in mebibytes (1,048,576 bytes) of the file currently being processed by the action (prior to any changes made by the action). Everywhere
%FILESIZEGB% Size in gigabytes (1,000,000,000 bytes) of the file currently being processed by the action (prior to any changes made by the action). Everywhere
%FILESIZEGIB% Size in gibibytes (1,073,741,824 bytes) of the file currently being processed by the action (prior to any changes made by the action). Everywhere
%SECTION% The text of the section being searched through. In the replacement text of the main action and extra processing, when using file sectioning.
%SECTIONLEFT% and %SECTIONRIGHT% The part of the text the section being searched through to the left or right of the search match the main action found in that section. In the replacement text of the main action and extra processing, when using file sectioning.
%SECTIONN% and %SECTIONNZ% The number of the section being searched through. %SECTIONN% starts counting at one, and %SECTIONNZ% at zero.

Example: Collect page numbers

In the search terms and replacement text of the main action and extra processing, when using file sectioning.
%SECTIONNA% The sequential letter of the section being searched through. The first section is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. In the search terms and replacement text of the main action and extra processing, when using file sectioning.
%LINE% The line being searched through In the replacement text of the main action and extra processing, when searching line by line.
%LINELEFT% and %LINERIGHT% The part of line being searched through to the left or right of the search match the main action found in that line In the replacement text of the main action and extra processing, when searching line by line.
%LINEN% and %LINENZ% The number of the line being searched through. %LINEN% starts counting at one, and %LINENZ% at zero. In the search terms and replacement text of the main action and extra processing, when searching line by line.
%LINENA% The sequential letter of the line being searched through. The first line is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. In the search terms and replacement text of the main action and extra processing, when searching line by line.
%MATCH% The search match

Examples: Padding replacements and Capitalize the first letter of each word

In the replacement text of the main action and extra processing.
%GROUP1%, %GROUP2%, etc. %GROUP1% is a backreference to a capturing group, equivalent to \1 in a regular expression or \1 and $1 in the replacement text. The advantage of %GROUP1% is that you can use the padding and case conversion specifiers listed below.

Example: Padding replacements

In any regular expression and any replacement text corresponding with a regular expression.
%MATCHSTART% The byte offset relative to the start of the file of the first character in the search match. Zero for a match at the very start of the file. In the replacement text of the main action and extra processing.
%MATCHSTOP% The byte offset relative to the start of the file of the first character after the search match. Equal to the size of the file for a match at the very end of the file. In the replacement text of the main action and extra processing.
%GROUP1START%, %GROUP2START%, etc. The byte offset relative to the start of the file of the first character of the text matched by capturing group number 1, 2, etc. For named capturing groups you can use %GROUPNAMESTART% where NAME is the name of the group. Group names are case sensitive. In any replacement text corresponding with a regular expression that has capturing groups.
%GROUP1STOP%, %GROUP2STOP%, etc. The byte offset relative to the start of the file of the first character after the text matched by capturing group number 1, 2, etc. For named capturing groups you can use %GROUPNAMESTOP% where NAME is the name of the group. Group names are case sensitive. In any replacement text corresponding with a regular expression that has capturing groups.
%MATCHN% and %MATCHNZ% The number of the search match. %MATCHN% starts counting at one, and %MATCHNZ% at zero. When used in the search term, the number indicates the number of the next match to be found, or one more than the number of matches already found when using %MATCHN%. When searching through more than one file, the numbering continues through the whole action. When searching for more than one search term, the matches for all search terms are numbered together. In the search terms and replacement text of the main action and extra processing.
%MATCHNA% The sequential letter of the search match. The first match is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. When used in the search term, the letter is the letter of the next match to be found. When searching through more than one file, the sequence continues through the whole action. When searching for more than one search term, the letters for all search terms form one sequence. In the search terms and replacement text of the main action and extra processing.
%MATCHFILEN% and %MATCHFILENZ% The number of the search match. %MATCHFILEN% starts counting at one, and %MATCHFILENZ% at zero. When used in the search term, the number indicates the number of the next match to be found, or one more than the number of matches already found. The numbering restarts at one (or zero) for each file searched through. When searching for more than one search term, the matches for all search terms are numbered together.

Examples: Add line numbers and Collect a numbered list

In the search terms and replacement text of the main action and extra processing.
%MATCHFILENA% The sequential letter of the search match. The first match is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. When used in the search term, the letter is the letter of the next match to be found. The sequence restarts with "a" for each file searched through. When searching for more than one search term, the letters for all search terms form one sequence. In the search terms and replacement text of the main action and extra processing.
%MATCHSECTIONN% and %MATCHSECTIONNZ% The number of the search match. %MATCHSECTIONN% starts counting at one, and %MATCHSECTIONNZ% at zero. When used in the search term, the number indicates the number of the next match to be found, or one more than the number of matches already found. The numbering restarts at one (or zero) for each line or each section searched through. When searching for more than one search term, the matches for all search terms are numbered together.

Example: Add line numbers

In the search terms and replacement text of the main action and extra processing, but only when using file sectioning.
%MATCHSECTIONNA% The sequential letter of the search match. The first match is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. When used in the search term, the letter is the letter of the next match to be found. The sequence restarts with "a" for each line or each section searched through. When searching for more than one search term, the letters for all search terms form one sequence. In the search terms and replacement text of the main action and extra processing, but only when using file sectioning.
%MATCHTERMN% and %MATCHTERMNZ% The number of the search match. %MATCHTERMN% starts counting at one, and %MATCHTERMNZ% at zero. When used in the search term, the number indicates the number of the next match to be found, or one more than the number of matches already found when using %MATCHTERMN%. When searching through more than one file, the numbering continues through the whole action. When searching for more than one search term, each search term has its own numbering sequence independent of the other search terms. In the search terms and replacement text of the main action and extra processing.
%MATCHTERMNA% The sequential letter of the search match. The first match is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. When used in the search term, the letter is the letter of the next match to be found. When searching through more than one file, the sequence continues through the whole action. When searching for more than one search term, each search term has its own lettering sequence independent of the other search terms. In the search terms and replacement text of the main action and extra processing.
%MATCHFILETERMN% and %MATCHFILETERMNZ% The number of the search match. %MATCHFILETERMN% starts counting at one, and %MATCHFILETERMNZ% at zero. When used in the search term, the number indicates the number of the next match to be found, or one more than the number of matches already found. The numbering restarts at one (or zero) for each file searched through. When searching for more than one search term, each search term has its own numbering sequence independent of the other search terms. In the search terms and replacement text of the main action and extra processing.
%MATCHFILETERMNA% The sequential letter of the search match. The first match is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. When used in the search term, the letter is the letter of the next match to be found. The sequence restarts with "a" for each file searched through. When searching for more than one search term, each search term has its own lettering sequence independent of the other search terms. In the search terms and replacement text of the main action and extra processing.
%MATCHSECTIONTERMN% and %MATCHSECTIONTERMNZ% The number of the search match. %MATCHSECTIONTERMN% starts counting at one, and %MATCHSECTIONTERMNZ% at zero. When used in the search term, the number indicates the number of the next match to be found, or one more than the number of matches already found. The numbering restarts at one (or zero) for each line or each section searched through. When searching for more than one search term, each search term has its own numbering sequence independent of the other search terms. In the search terms and replacement text of the main action and extra processing, but only when using file sectioning.
%MATCHSECTIONTERMNA% The sequential letter of the search match. The first match is "a", the second "b", etc. Enter the placeholder in upper or lowercase to determine the case of the letter. When used in the search term, the letter is the letter of the next match to be found. The sequence restarts with "a" for each line or each section searched through. When searching for more than one search term, each search term has its own lettering sequence independent of the other search terms. In the search terms and replacement text of the main action and extra processing, but only when using file sectioning.
%TERMN% and %TERMNZ% The number of the search term in the list of search terms or the delimited search terms in the main part of the action that is being searched for or that found the match being replaced or collected. The number depends solely on the order of the search terms in the main part of the action as you entered them on the Action panel. %TERMN% starts counting at one, and %TERMNZ% at zero. In the search terms and replacement text of the main action and extra processing.
%TERMNA% The sequential letter of the search term in the list of search terms or the delimited search terms in the main part of the action that is being searched for or that found the match being replaced or collected. The letter depends solely on the order of the search terms in the main part of the action as you entered them on the Action panel. In the search terms and replacement text of the main action and extra processing. Enter the placeholder in upper or lowercase to determine the case of the letter.
%MATCHCOUNT%
(collect)
The number of times a particular search match was found. This placeholder is substituted at the end of "collect data" actions that group unique matches. The placeholder is replaced with the number of items that the same piece of text was collected. Only available in the text to be collected of "collect data" actions, and only when grouping identical matches.
%MATCHCOUNT%
(footers)
The number of matches found in a file when used in source file footers. The number of matches written to a target file when used in target file footers. Only available in file footers when collecting headers and footers.
%FILECOUNT% The number of source files that had their matches written to a target file. Only available in target file footers when collecting headers and footers.
%GUID% Generates a new GUID in the form of {067F8296-9D1F-4CF2-87E0-70EFC4CE41BF} each time a replacement is made. In the replacement text of the main action and extra processing.
%GUIDFILE% Generates a new GUID for each file searched through. The GUID stays constant when the placeholder is used multiple times for the same file. In replacement text, text to be collected, and file headers and footers.
%GUID1% to %GUID9% Generates nine different GUIDs each time an action or sequence is executed. The nine GUIDs stays constant throughout the execution of the action or sequence. In replacement text, text to be collected, and file headers and footers.

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 upper case.

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. The A or "alpha" padding style puts letters "a" before the placeholder's value. This style is useful for padding sequence letters like %MATCHNA%.

Padding style letters are case insensitive, except for the "alpha" style. %matchna:6a% uses lowercase letters, and %MATCHNA:6A% uses uppercase letters.

Examples: Padding replacements and Padding and unpadding CSV files

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.

Instead of a case conversion specifier, you can use the case adaptation specifier. It consists of A followed by a digit (not to be confused with a number followed by A, which is a padding specifier). This specifier is only available in a replacement text corresponding with a regular expression. You can use the specifier to give the placeholder the same casing style as the regular expression match or the text matched by a capturing group. Specify zero for the whole regex, or the backreference number of a capturing group. E.g. %MATCH:A2% inserts the whole regular expression match, converted to the case used by the second capturing group. The case adaptation specifier detects and adapts to uppercase, lowercase, initial caps and first cap. If the referenced capturing group uses a mixed casing style, the placeholder's value is inserted unchanged.

Example: Capitalize the first letter of each word

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.