Pattern Syntax#
NeoMutt uses patterns to select messages and aliases. This document covers both pattern systems: message patterns (used throughout NeoMutt for filtering, coloring, scoring, and hooks) and alias patterns (used in the alias dialog).
Message Patterns#
Message patterns are the primary pattern system in NeoMutt. They are used by many commands and configuration directives:
limitβ filter the index viewtag-pattern/untag-patternβ tag or untag messagesscoreβ assign scores to messagescolor indexβ colorize messages in the indexfolder-hook,message-hook,reply-hook,send-hook,send2-hookβ hookspushand macro commands that reference patterns
General Syntax#
A pattern is composed of one or more pattern terms, optionally connected by logical operators. Each term consists of a prefix character, a pattern letter, and (for some patterns) an argument.
~X [ARGUMENT]
β β
β βββ pattern letter (e.g., f for From, s for Subject)
βββββ prefix character (~, =, or %)
Pattern Prefixes#
Patterns use three prefix characters to control matching behavior:
Prefix |
Name |
Argument Type |
Description |
|---|---|---|---|
|
Standard |
REGEX |
Matches using a POSIX regular expression |
|
IMAP server-side |
STRING |
Matches using substring comparison (IMAP only) |
|
Address group |
GROUP |
Matches against a named address group |
Examples:
# Standard regex match: From contains "alice"
color index green default "~f alice"
# IMAP server-side match: body contains "project update"
color index cyan default "=b project update"
# Address group match: From is a member of the "work" group
color index yellow default "%f work"
Logical Operators and Grouping#
Multiple pattern terms can be combined using logical operators:
Operator |
Meaning |
Example |
|---|---|---|
(implicit) |
AND |
|
|
OR |
|
|
NOT |
|
|
Grouping |
|
|
All addresses |
|
|
Alias mode |
Marks the pattern for alias matching |
Operator precedence (highest to lowest): !, implicit AND, |.
Use parentheses to override precedence.
# Tag messages that are new and flagged
tag-pattern "~N ~F"
# Color messages that are either new or flagged
color index brightred default "~N | ~F"
# Score messages that are not deleted and not read
score "!~D !~R" +5
# Limit to messages where ALL To: recipients are at example.com
limit "^~t @example\\.com$"
# Complex grouping: unread messages from Alice or Bob
color index cyan default "(~f alice | ~f bob) ~U"
Flag Patterns (No Argument)#
These patterns match on message flags and properties. They take no argument.
Pattern |
Description |
|---|---|
|
All messages |
|
Deleted messages |
|
Expired messages |
|
Flagged (important/starred) messages |
|
Cryptographically signed messages |
|
Cryptographically encrypted messages |
|
Messages containing a PGP key |
|
Messages addressed to a known mailing list |
|
New messages |
|
Old messages (seen in previous session, but not read) |
|
Messages addressed to you |
|
Messages from you |
|
Messages which have been replied to |
|
Read messages |
|
Superseded messages |
|
Tagged messages |
|
Messages addressed to a subscribed mailing list |
|
Unread messages (combines |
|
Messages part of a collapsed thread |
|
Cryptographically verified messages |
|
Broken threads (missing parent) |
|
Unreferenced messages (not referenced by other messages) |
|
Duplicated messages (same |
Examples:
# Color flagged messages bright yellow
color index brightyellow default "~F"
# Limit view to unread messages only
# (type 'l' in the index, then enter:)
# ~U
# Score new messages from mailing lists
score "~N ~l" +10
# Tag all deleted messages
tag-pattern "~D"
# Color encrypted messages
color index brightmagenta default "~G"
# Find duplicate messages
limit "~="
Address and Header Patterns (Regex Argument)#
These patterns take a regular expression argument for ~ prefix, a plain
string for = prefix, or an address group name for % prefix.
Pattern |
|
|
Matches against |
|---|---|---|---|
|
|
Message body |
|
|
|
Entire message (headers + body) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
All headers (raw) |
|
|
Spam header ( |
||
|
|
||
|
|
||
|
|
|
|
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
Message tags |
Examples:
# Color messages from anyone at example.com
color index green default "~f @example\\.com"
# Limit to messages with "budget" in the subject
# (type 'l' in the index, then enter:)
# ~s budget
# Score messages where you are in Cc
score "~c your@email\\.com" +3
# Color messages addressed to any recipient matching a pattern
color index blue default "~C @dev\\.example\\.org"
# Find messages with PDF attachments
limit "~M application/pdf"
# Color messages referencing a specific Message-ID
color index cyan default "~x 20240315\\.abc123@mail\\.example\\.com"
# Match messages tagged with "important"
color index brightyellow default "~Y important"
# Body search for a specific phrase
limit "~b quarterly report"
# Color messages from members of the "colleagues" address group
color index green default "%f colleagues"
# Use with hooks: auto-flag messages from your boss
message-hook "~f boss@company\\.com" "set scoring=yes"
Date Patterns#
Date patterns filter messages by when they were sent or received.
Pattern |
Description |
|---|---|
|
Date the message was sent ( |
|
Date the message was received |
Relative Date Offsets#
Relative offsets compare the message date to the current time:
Syntax |
Meaning |
|---|---|
|
Less than 3 days ago |
|
More than 3 days ago |
|
Exactly 3 days ago |
Offset Units#
Unit |
Meaning |
|---|---|
|
Years |
|
Months |
|
Weeks |
|
Days |
|
Hours |
|
Minutes |
|
Seconds |
Absolute Dates#
Absolute dates can be specified in DD/MM/YYYY format (month and year are
optional and default to the current month/year) or ISO 8601 YYYYMMDD format:
Example |
Meaning |
|---|---|
|
10th of the current month |
|
10th of December, current year |
|
10th of December, 2024 |
|
10th of December, 2024 (ISO 8601) |
Date Ranges#
Two dates separated by - define an inclusive range:
Example |
Meaning |
|---|---|
|
January 1 to December 31, 2024 |
|
Same range in ISO 8601 format |
|
June 1, 2024 until now |
Mixed Date-Offset Ranges#
A date and an offset can be combined:
Example |
Meaning |
|---|---|
|
From 3 days ago to 2 days from now |
|
June 1, 2024 minus 3 days (May 29) |
|
June 1, 2024 plus 2 weeks (June 15) |
|
2 weeks in both directions from today |
Examples:
# Color messages received in the last 24 hours
color index brightgreen default "~r <1d"
# Limit to messages sent in the past week
# (type 'l' in the index, then enter:)
# ~d <1w
# Score messages older than 6 months
score "~d >6m" -5
# Color messages from a specific date range
color index cyan default "~d 1/1/2025-31/3/2025"
# Find messages received more than a year ago
limit "~r >1y"
# Messages sent in the last 2 hours
limit "~d <2H"
# Messages within a 1-month window centered on today
limit "~d *1m"
Range Patterns#
Range patterns match on numeric properties of messages.
Pattern |
Description |
|---|---|
|
Message number in the mailbox |
|
Message score |
|
Number of MIME attachments |
|
Message size (in bytes) |
Range Syntax#
Syntax |
Meaning |
|---|---|
|
Exactly 100 |
|
Between 10 and 100, inclusive |
|
Up to 100 (0 to 100) |
|
100 or more |
|
Less than 100 (exclusive) |
|
Greater than 100 (exclusive) |
Size Suffixes (for ~z only)#
Suffix |
Meaning |
|---|---|
|
Kilobytes (Γ1024) |
|
Megabytes (Γ1048576) |
Examples:
# Color large messages (over 1 megabyte)
color index brightred default "~z >1M"
# Limit to messages with attachments
# (type 'l' in the index, then enter:)
# ~X >0
# Score messages with high scores even higher
score "~n >50" +10
# Color small messages (under 10 kilobytes)
color index white default "~z <10K"
# Limit to messages 50 through 100
limit "~m 50-100"
# Find messages with exactly 3 attachments
limit "~X 3"
# Messages between 100K and 500K
color index yellow default "~z 100K-500K"
Thread Patterns#
Thread patterns match messages based on their position in a thread hierarchy.
Pattern |
Description |
|---|---|
|
Messages in threads containing a message that matches PATTERN |
|
Messages whose immediate parent matches PATTERN |
|
Messages having a direct child that matches PATTERN |
Examples:
# Color all messages in threads that contain a flagged message
color index yellow default "~(~F)"
# Limit to threads containing messages from your boss
limit "~(~f boss@company.com)"
# Find messages whose parent was from Alice
limit "~<(~f alice@example.com)"
# Find messages that have a reply from Bob
limit "~>(~f bob@example.com)"
# Color entire threads that contain unread messages
color index brightcyan default "~(~U)"
# Combine with other patterns: threads with flagged messages, but only show unread
limit "~(~F) ~U"
IMAP Server-Side Patterns#
When connected to an IMAP server, the = prefix performs server-side string matching.
This is faster than downloading messages for local regex matching, but only supports substring comparison (not regular expressions).
Pattern |
Description |
|---|---|
|
Body contains STRING |
|
Headers or body contain STRING |
|
Headers contain STRING |
|
Gmail custom server-side search (Gmail only) |
The =/ STRING pattern is specific to Gmailβs IMAP implementation and passes the string directly to Gmailβs search engine, supporting Gmailβs search operators.
Examples:
# IMAP server-side body search (faster than ~b for IMAP)
limit "=b project deadline"
# Gmail-specific search using Gmail operators
limit "=/ has:attachment larger:5M"
# Server-side header search
limit "=h X-Mailer: Thunderbird"
Regex Case Sensitivity#
NeoMutt uses smart case matching for regular expressions:
If the regex contains only lowercase characters, matching is case-insensitive
If the regex contains any uppercase character, matching is case-sensitive
# Case-insensitive: matches "alice", "Alice", "ALICE"
~f alice
# Case-sensitive: matches only "Alice" (not "alice" or "ALICE")
~f Alice
# Case-insensitive: all lowercase, matches "urgent", "Urgent", "URGENT"
~s urgent
# Case-sensitive: uppercase letter present, matches only "URGENT"
~s URGENT
Simple Search Shortcuts#
When a search string does not start with ~, =, or %, it is treated as a βsimple searchβ.
NeoMutt expands it using the $simple_search variable.
The default value of $simple_search is ~f %s | ~s %s, where %s is replaced with the search string.
This means a plain search term like alice becomes ~f alice | ~s alice, searching both the From: and Subject: fields.
# Set a custom simple search to also search the body
set simple_search = "~f %s | ~s %s | ~b %s"
Special Simple Search Keywords#
Certain keywords are recognized and expanded to flag patterns:
Keyword |
Expands to |
Meaning |
|---|---|---|
|
|
All messages |
|
|
All messages |
|
|
All messages |
|
|
Deleted messages |
|
|
Flagged messages |
|
|
New messages |
|
|
Old messages |
|
|
Replied-to messages |
|
|
Read messages |
|
|
Tagged messages |
|
|
Unread messages |
These keywords work in the limit command. For example, typing l then entering new is equivalent to entering ~N.
Alias Patterns#
Alias patterns are a separate pattern system used exclusively in the alias dialog.
When you open the alias dialog and use limit, tag-pattern, or untag-pattern, patterns are interpreted as alias patterns, not message patterns.
Supported Operators#
Only four pattern operators are supported in alias mode:
Pattern |
Matches against |
|---|---|
|
Alias name (the short identifier/key) |
|
Alias address list (email addresses) |
|
Alias comment (descriptive text) |
|
Alias tags |
Important: Although alias patterns reuse the same
~f,~t, and~csyntax as message patterns, they match against completely different fields. In message patterns,~fmatches the From: header; in alias patterns,~fmatches the alias name.
Examples:
# In the alias dialog, limit to aliases whose name contains "work"
~f work
# Find aliases with addresses at example.com
~t @example\.com
# Find aliases with "team lead" in the comment
~c team lead
# Find aliases tagged as "project-alpha"
~Y project-alpha
# Combine: aliases named "dev" with addresses at example.org
~f dev ~t @example\.org
# Either work aliases or personal aliases
~f work | ~f personal
# Aliases NOT tagged as "archived"
!~Y archived
Alias Simple Search#
When a plain string is entered in the alias dialog (without a ~, =, or % prefix), it is expanded using the built-in alias simple search:
~f %s | ~t %s | ~c %s
This searches the alias name, addresses, and comment simultaneously. For
example, entering john in the alias dialog limit prompt is equivalent to:
~f john | ~t john | ~c john
Differences from Message Patterns#
Feature |
Message Patterns |
Alias Patterns |
|---|---|---|
|
Matches From: header |
Matches alias name |
|
Matches To: header |
Matches alias addresses |
|
Matches Cc: header |
Matches alias comment |
|
Matches message tags |
Matches alias tags |
Flag patterns ( |
Supported |
Not supported |
Date patterns ( |
Supported |
Not supported |
Range patterns ( |
Supported |
Not supported |
Thread patterns ( |
Supported |
Not supported |
Body/header search ( |
Supported |
Not supported |
IMAP patterns ( |
Supported |
Not supported |
Group patterns ( |
Supported |
Not supported |
Logical operators ( |
Supported |
Supported |
Simple search |
Configurable via |
Fixed: |
Note: Unsupported operators in alias mode will silently fail to match any alias. No error is reported.
Quick Reference#
Pattern Prefixes#
Prefix |
Type |
Argument |
|---|---|---|
|
Standard |
Regular expression |
|
IMAP server-side |
Substring |
|
Address group |
Group name |
All Message Pattern Operators#
Pattern |
Argument |
Description |
|---|---|---|
|
β |
All messages |
|
REGEX |
Body matches |
|
REGEX |
Entire message matches |
|
REGEX |
|
|
REGEX |
|
|
DATE |
Sent date |
|
β |
Deleted |
|
REGEX |
|
|
β |
Expired |
|
REGEX |
|
|
β |
Flagged |
|
β |
Cryptographically signed |
|
β |
Cryptographically encrypted |
|
REGEX |
Headers match |
|
REGEX |
Spam header matches |
|
REGEX |
|
|
QUERY |
External search query |
|
β |
Contains PGP key |
|
REGEX |
|
|
β |
To known mailing list |
|
REGEX |
Any address field matches |
|
RANGE |
Message number |
|
REGEX |
Content-Type matches |
|
RANGE |
Score |
|
β |
New |
|
β |
Old |
|
β |
Addressed to you |
|
β |
From you |
|
β |
Replied to |
|
DATE |
Received date |
|
β |
Read |
|
REGEX |
|
|
β |
Superseded |
|
REGEX |
|
|
β |
Tagged |
|
β |
To subscribed mailing list |
|
β |
Unread |
|
β |
Collapsed thread |
|
β |
Cryptographically verified |
|
REGEX |
|
|
REGEX |
|
|
RANGE |
Number of attachments |
|
REGEX |
|
|
REGEX |
Tags match |
|
RANGE |
Message size |
|
β |
Broken thread |
|
β |
Unreferenced message |
|
β |
Duplicate (same |
|
PATTERN |
Thread contains match |
|
PATTERN |
Parent matches |
|
PATTERN |
Child matches |
Logical Operators#
Operator |
Meaning |
|---|---|
(space) |
AND |
|
OR |
|
NOT |
|
Grouping |
|
All addresses must match |
Date Range Quick Reference#
Syntax |
Example |
Meaning |
|---|---|---|
|
|
Within the last 7 days |
|
|
More than 30 days ago |
|
|
Exactly 1 day ago |
|
|
Specific date |
|
|
Specific date (ISO 8601) |
|
|
Date range |
|
|
Β±2 weeks from today |
Number Range Quick Reference#
Syntax |
Example |
Meaning |
|---|---|---|
|
|
Exactly 5 |
|
|
Between 10 and 50 |
|
|
Up to 100 |
|
|
100 or more |
|
|
Less than 10 |
|
|
Greater than 100 |
|
|
Kilobytes / Megabytes (size only) |
Alias Pattern Operators#
Pattern |
Matches |
|---|---|
|
Alias name |
|
Alias addresses |
|
Alias comment |
|
Alias tags |