How to Delete Repeated Words
Repeated words, such as "the the", are a common error that's easy to overlook when editing text documents. PowerGREP makes such mistakes easy to find and correct.
- Select the files you want to search through in the File Selector.
- Start with a fresh action.
- Set the action type to "search and replace". Leave the search type as "regular expression".
- In the Search box, enter the regular expression \b(\w+)(\s+\1\b)+ and make sure to leave "case sensitive search" off. This regex matches a word and its repetitions. The word is stored into a capturing group. The word boundaries make sure we don't match partial words, such as he in the helmet.
- Enter \1 as the replacement text. This backreference will be substituted with the contents of the first capturing group, in this case the repeated word.
- Set the target and backup file options as you like them.
- Click the Preview button to run the action. PowerGREP will find all repeated words, but will not actually replace them.
- On the Results panel, see if "per file" is selected in "group search matches". If not, select it and click the Update button.
- Double-click on one of the files in the results to open it in PowerGREP's editor.
- In the editor, use Next Match and Make Replacement to delete repeated words. The editor is a full-featured text editor. You can edit the file in any way you want. PowerGREP automatically keeps track of the search matches (i.e. repeated words) while you edit.
- Save the file in the editor, and repeat from step 9 to edit all other files.
PowerGREP's full-featured built-in editor makes it very easy to decide for each individual search match whether to replace it. You don't have to click Yes/No for each search match in the order that PowerGREP finds them, like most other search-and-replace tools force you to.
You can also work the other way around. In step 7, click the Replace button to delete all repeated words. In step 12, use the Revert button to undo individual search matches.