The Drafts editor supports find and replace in the text in a draft, with basic matching, as well as advanced regular expression matching.
To access find and replace:
- On iOS:
- On Mac:
Edit > Find > Find..from the main menu, or use the associated
In the find window, enter your search text, and select find to find occurences of that string. Any results will be displayed below, with a preview of the text surrounding the found text, and an indicator of the line number where that text occurs. Each of these results has two commands:
- Select: Close the find results and jump to that result in the editor with its text selected.
- Replace: Replace the occurrence of the text with the value in the “Replace” field. This will also update the results of the find.
The Replace all button at the top will replace every occurrence in the results.
In addition to basic finds, the find and replace feature has a couple of additional options, which can be viewed by tapping the “Show options” button. Including toggling whether the search is case-sensitive, and more importantly, the ability to enable regular expressions.
For those familiar, know that Drafts implementation is based on NSRegularExpression and any documentation on its syntax is applicable. With regular expressions enabled, the replace value supports capture group expressions in the format
n is the match index. This can be very useful for swapping values and similar operations.
As a simplified example, assume a draft with the following content:
Smith, Jim Jones, Jane
Using a regular expression of
^([A-Za-z]*), ?([A-Za-z]*) in the find, would find two results. This expression, roughly explained, says find alpha-characters, then a comma and optional space, and then any remaining alpha-characters following. The parentheses indicate capture groups that can be re-used in the replacement value, using
$n where n is the order of the capture groups. Running replace all on this find, with
$2 $1 in the replace text, would result in the draft:
Jim Smith Jane Jones
The capture group values for each find result were substituted for the placeholders in the replace text, and effectively swapped.
A full explanation of regular expression is beyond this help page, but please ask in the community forums for assistance.