Link Search Menu Expand Document

Find and Replace

The Drafts editor supports find and replace in the text in a draft, with basic matching, as well as advanced regular expression matching.

Table of Contents

  1. Using Find and Replace
  2. Advanced Options
  3. Regular Expression Example

Using Find and Replace

To access find and replace:

  • On iOS:
    • On the action bar, tap the selection and commands button to the far left, and select “Find…”.
    • Or, use the keyboard shortcut ⌘-F on an external keyboard.
    • Or, use an action (like this example) which opens the find window.
  • On Mac:
    • Select Edit > Find > Find.. from the main menu, or use the associated ⌘-F keyboard shortcut.

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.

iOS Mac

editor/find

Advanced Options

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.

If you have advanced search needs and are not familiar with regular expressions, there are some great resources around the web.

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 where n is the match index. This can be very useful for swapping values and similar operations.

Regular Expression Example

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.


Download on App Store Download on Mac App Store

© 2012-2022 by Agile Tortoise, Inc.
Drafts is a registered Trademark of Agile Tortoise, Inc.
Privacy | Terms