Padding Replacements

PowerGREP's match placeholders make it easy to pad the replacement text in a search and replace action, or the text to be collected in a "collect data" action. If the text to be collected is simply a regular expression match or a single capturing group, you can use the padding specifiers directly in the main action. If the replacement text is more complex, you can use PowerGREP's extra processing feature to pad it.

  1. Select the files you want to process in the File Selector.
  2. Select a file format configuration such as "none" or "writable proprietary formats" that does not enable and read-only converters.
  3. Start with a fresh action.
  4. Set the action type to "search and replace" or "collect data". Leave the search type as "regular expression".
  5. Enter the regular expression that matches the items you want to collect or replace. Use capturing groups to extract specific parts of each record.

For the replacement text or text to be collected, you have two options: the whole regex match or a single capturing group, or something more complex. For the whole match or a single group, you can use a match placeholder with padding specifier directly:

  1. As the replacement text or text to be collected, enter %MATCH:6L% or %GROUP1:6L%. Use %MATCH% for the whole match, or %GROUP1% for the capturing group with index 1, %GROUP2% for group #2, etc. :6L is the padding specifier. This one pads up to 6 spaces at the left. Use R instead of L to pad at the right, C for center, Z for zero-padding at the left, and A for a-padding at the left. Enter any number instead of 6 to set the length the final replacement should have.
  2. Set the target and backup options as you want.
  3. Click the Preview button to check the results.

If the replacement text is a combination of multiple capturing groups and/or literal text, you'll need to use extra processing:

  1. As the replacement text or text to be collected, without regard to padding.
  2. Turn on the "extra processing" option.
  3. Leave the extra processing search type as "regular expression", and turn on the option "dot matches newlines".
  4. In the "extra processing search" box, enter the regular expression .++. This regular expression matches the entire replacement text from step 5.
  5. As the "extra processing replacement", enter %MATCH:12L% to pad the replacement up to 12 spaces at the left. Use R instead of L to pad at the right, C for center, Z for zero-padding at the left, and A for a-padding at the left. Enter any number instead of 12 to set the length the final replacement should have.
  6. Set the target and backup options as you want.
  7. Click the Preview button to check the results.