How can I filter messages in Gmail using boolean OR
conditions? For example, I can specify addresses in the To:
or From:
fields, but this only matches emails that meet both criteria. How can I match emails that meet one or both criteria?
5 Answers
To filter Gmail messages using the boolean OR condition, use any of the following in the search field:
OR
(case sensitive)- Braces
{}
- Pipe
|
(undocumented)
Examples:
from:xyz OR to:uvw
{from:xyz to:uvw}
from:xyz | to:uvw
To create a filter from that search, select the little down arrow on the right side of the search field and then click
create filter with this search
.
See the Search Operator table in GMail help > Refine searches in Gmail.
-
This answer is not correct. If you try to create a filter from one of these examples, Gmail will generate a poorly formed AND filter Commented Jul 18 at 21:43
-
@SteveDeWald: so, support.google.com/mail/answer/… is somewhat wrong?– akiraCommented Jul 31 at 18:29
-
The support document you linked discusses search operators, but those do not work for filters. The original question asked about filters. Commented Aug 14 at 18:47
If you are talking about searching, then @akira's answer is correct. However, it sounds like you are asking about how to use this condition in a filter.
The trick is that you can put whatever search criteria you want in the filter's Has the words field. For any other field it will prefix your criteria with the field name. For example, if you type [email protected]
in the To field, it'll create the filter condition to:([email protected])
. The reason it works in the Has the words field, is because it doesn't prefix it with anything. This allows you to specify your own prefixes and even mix different ones like to:
and from:
as you would in the normal search.
- Create or modify a filter.
- In the Has the words field, enter your
OR
condition. For example:to:[email protected] OR from:[email protected]
This is also the place to put any other attributes you want to match (e.g. label:
, in:
, etc.).
This will also work in the Show search options page, however it's easier to just use a normal search instead.
To my surprise, the solution to me was using the vertical bar |
between emails instead of the comma ,
in the TO
filed during filter creation.
Example:
[email protected] | [email protected] | [email protected]`
The search box would look like:
to:([email protected] | [email protected] | [email protected])
I got a popup message from Gmail saying that using special characters may give unexpected results. Just clicked on continue and it worked perfectly.
Gmail accepts several syntaxes:
apple OR orange
{apple orange}
apple | orange
Personally, I like to use braces {}
because it is more concise:
from:{john jane joe}
The following are also equivalent:
from:(john | jane | joe)
from:(john OR jane OR joe)
For the question asked, I would use:
{to:john from:jane}
-
The best way I've got to work for the
to
field is:to:{[email protected] [email protected] [email protected]}
– c24wCommented Jan 28, 2019 at 11:08 -
You can also perform boolean OR searches between groups of words.
Parentheses ()
group terms while quotations ""
instruct Gmail to search for the exact words or phrase:
("Some Words1" "Some Words2") OR ("Some Words1" "Some Words3")
Instead of separating the groups using OR, the groups can be enclosed in braces {}
to achieve the same effect:
{("Some Words1" "Some Words2")("Some Words1" "Some Words3")}