Links

contains

Learn how to use the contains function in Notion formulas.
The contains() function tests whether the first argument contains the second argument. It only accepts strings (or nested functions that output strings).
1
contains(string)
contains() tests for the entire string passed via the second argument, is case-sensitive, and does not accept regular expressions.
Good to know: The test function can do everything contains() does and much more, including accepting regular expressions and testing non-string data types.

Example Formula

1
contains("Monkey D. Luffy", "Luffy") // Output: true
2
3
contains("Monkey D. Luffy", "keyLuf") // Output: false
4
5
// Invalid
6
contains(true, "true") // Error: Type mismatch true is not a Text.

Example Database

This example database contains some file attachments. The Meta formula property displays information about each file, including its media type and hosting location (within Notion or hosted externally).

View and Duplicate Database

“Meta” Property Formula

1
// Compressed
2
if(contains(prop("File"),"jpg") or contains(prop("File"),"png") or contains(prop("File"),"gif") or contains(prop("File"),"jpeg"),"🌅 Image",if(contains(prop("File"),"mp3") or contains(prop("File"),"wav") or contains(prop("File"),"aiff"),"🎧 Audio","📝 Text")) + "\n" + if(contains(prop("File"),"secure.notion-static.com"),"✅ Internal","⛔️ Externally Hosted")
3
4
// Expanded
5
if(
6
contains(
7
prop("File"),
8
"jpg"
9
) or contains(
10
prop("File"),
11
"png"
12
) or contains(
13
prop("File"),
14
"gif"
15
) or contains(
16
prop("File"),
17
"jpeg"
18
),
19
"🌅 Image",
20
if(
21
contains(
22
prop("File"),
23
"mp3"
24
) or contains(
25
prop("File"),
26
"wav"
27
) or contains(
28
prop("File"),
29
"aiff"
30
),
31
"🎧 Audio",
32
"📝 Text"
33
)
34
) +
35
"\n" +
36
if(
37
contains(
38
prop("File"),
39
"secure.notion-static.com"
40
),
41
"✅ Internal",
42
"⛔️ Externally Hosted"
43
)
File & Media-type properties return their file path as a string when referenced in Notion formulas.
This formula uses contains() to check each file’s path for the presence of several common file extensions, such as jpg, gif, mp3, etc.
It uses a nested if statement , as well as the or operator, to check for several different file extensions. It then outputs the file’s media type based on its match (or lack thereof).
Another if statement checks for the presence of the string secure.notion-static.com, which is always part of the URL for files that are uploaded directly to Notion’s Amazon AWS locker.
Note: One major weakness of contains() is that it can’t do case-insensitive matching. In this formula, we’d have to add many more “or” clauses in order to test for every case variation of each file type. Check out the test function’s example database to see a much more efficient way to achieve this exact same goal.

Other formula components used in this example:

About the Author

My name is Thomas Frank, and I'm a Notion-certified writer, YouTuber, and template creator. I've been using Notion since 2018 to organize my personal life and to run my business and YouTube channel. In addition to this formula reference, I've created a free Notion course for beginners and several productivity-focused Notion templates. If you'd like to connect, follow me on Twitter.
Last modified 4mo ago