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).

contains(string, string) string.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: contains will accept non-string data types for both the first and second argument. They will be converted to strings before comparing.

Good to know: The test function can do everything contains() does and much more, including accepting regular expressions and testing non-string data types.

contains("Monkey D. Luffy", "Luffy") /* Output: true */ "Monkey D. Luffy".contains("keyLuf") /* Output: false */ contains(true, "true") /* Output: true */ contains("There are 10 members.", 10) /* Output: true */

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).

Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
A new tool that blends your everyday work apps into one. It’s the all-in-one workspace for you and your team
thomasfrank.notion.site
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" )

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:

if – Thomas Frank
thomasjfrank.com
add – Thomas Frank
thomasjfrank.com
or – Thomas Frank
thomasjfrank.com
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.

🤔 Have an UB Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas

🤔 Have a Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas