Replacement Expressions

Replacement expressions are very simple formulas, used with regular expressions, that enable you to construct replacements for text that you find when you search files with Finders Keepers™.  Replacement expressions, as illustrated below, correspond to curly-bracketed parts of a regular expression.  They enable you to replace particular parts of text that regular expressions find in files.   Finders Keepers regular expressions file searches

Regular expressions entered in Find in the main window are independent of what you enter in Replace.  But replacement expressions, entered in Replace in the main window, are completely dependent on what you enter in Find.  Replacement expressions refer to one or more parts, or all, of the regular expression in Find.  So, you can use replacement expressions to replace text only if you are using regular expressions to search files.

For replacement expressions to work at all, the regular expression in Find must have pairs of curly brackets { } enclosing the sub-expressions or the complete expression.  The enclosed sub-expressions may be referenced sequentially, left to right, as \1, \2, and so on, up to \9.  For example, given a regular expression in Find of {whale}{[']?[s]?}, a replacement expression in Replace of white whale\2 will replace occurrences of “whale”, “whales”, and “whale’s” with “white whale”, “white whales”, and “white whale’s”, respectively.

Replacement Expression Symbols

Symbol

Description

&

 

Put an ampersand into your replacement expression to insert all the matched text into the replacement text at the position of the ampersand.

 

\0

 

A backslash zero has the same effect as an ampersand.

 

\1 .. \9

 

Put a backslash number, for example, \1, \2, \3, corresponding to a sub-expression in your regular-expression Find, into your replacement expression to insert the sub-expression’s matched text.   The number must be between 1 and 9 to refer to a sub-expression.

You might want to look at some more replacement examples.

Finders Keepers™ has other ways to look for words and phrases:  take a look at the 4 ways to find.