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. Basic Find and Replace
  2. Advanced Find and Replace
    1. Advanced Options
    2. Regular Expression Example

Basic Find and Replace

By default, Drafts uses system find and replace support for simplicity and consistency with other apps – both on iOS and Mac.

To access find and replace:

  • On iOS:
    • On the action bar, tap the selection and commands button to the far left, and select the magnifying glass icon.
    • Tap and hold on the quick search button at the top right for menu options, select “Find in Draft…”.
    • 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.
    • Or, use the keyboard shortcut ⌘-F on an external keyboard.
    • Or, use an action (like this example) which opens the find window.

Once displayed, the find bar allows you to enter text. Matching strings in the editor will be highlighted, and the arrow keys allow you to easily page through results.

The find interface also allows expansion to display a replace field, and supports replacing matches in the text.

Advanced Find and Replace

If you have need to find and replace using advanced tools like regular expressions and case-matching, Drafts provides an advanced find interface.

Features supported by the advanced find window not available in standard find:

  • Restorable history of find requests.
  • Support for regular expressions and case-sensitive matching.
  • Overview display of match results.

To access advanced find:

  • On iOS:
    • Tap and hold on the quick search button at the top right for menu options, select “Advanced Find…”.
    • Or, use an action (like this “Advanced Find” example) which opens the advanced find window.
  • On Mac:
    • Enable Edit > Find > Use Advanced Find from the main menu, then use the Edit > Find > Find... command (or associated ⌘-F keyboard shortcut).
    • Or, use an action (like this “Advanced Find” example) which opens the advanced find window.

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.


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

Mastodon