Notion supports the use of regular expressions in three functions:
- test – tests whether a string contains a regular expression. Outputs a Boolean true or false value.
- match — returns all matches of the regular expression as a list.
- replace – matches a single instance of a regular expression within a string and replaces it with a specified replacement string.
- replaceAll – matches all instances of a regular expression and replaces them with a specified replacement string.
By using regular expressions within these functions, it is possible to do many kinds of string manipulation within Notion formulas.
What Is a Regular Expression?
A regular expression (often called a regex) is simply a set of instructions that tells a regular expression engine how to search through an input string in order to find one or more matches.
Regular expressions can often look very complex:
Code language: JavaScript (javascript)
However, they can also be very simple. This is also a regular expression:
Code language: JavaScript (javascript)
This expression would tell the regex engine to search the input string for a sub-string that matches “cat”. The replace function then replaces it with “dog”.
A simple match like this could also be found using the contains function:
Code language: JavaScript (javascript)
But what if you need to be more flexible with your search criteria?
Take this problem, for instance: Which of these strings contains the word “cat”?
- I have six cats.
- My dog catches fish.
- Cat food is expensive.
Here, contains()
runs into trouble (see this in an example database):
Code language: JavaScript (javascript)
contains()
gets the first one right, but fails on the other two.
On the second string, it sees “cat” inside the word “catches”. On the third string, it fails to see “Cats” because contains()
is case-sensitive.
This is where a regular expression can help us!
Regular expressions let us define character groups, make characters optional, check for word boundaries, and so much more.
Here’s how you could check all three of these strings correctly using the test function:
Code language: JavaScript (javascript)
The regular expression we’re checking for here is \b[Cc]ats?\b
. Let’s break it down:
\b
is a special character that translates to “word boundary”. It’s not a space character; it’s the boundary between a word character and a non-word character. In Notion, word characters includeA-z
,0-9
, and_
.[Cc]
is a character class. The brackets[]
define a group of characters (C
andc
), and the regex engine will try to match any one of them. This allows us to check for both “Cat” and “cat”.?
denotes that the preceding character is optional. It can appear zero or one times in the match. Since thes
precedes it, this allows us to include the plural “cats” as well as the singular “cat”.
Breaking all this down to plain English, our regular expression is essentially saying:
Match any of the words “Cat, cat, Cats, or cats”.
Doing this with contains()
would be really inefficient. You’d need to string together many, many contains()
instances using or clauses in order to account for the many variables – not just plurality and capitalization, but word boundaries as well!
By giving us special characters to work with, regular expressions essentially give us a new language that we can use to define exactly what we’re looking for in the input string.
Once we’ve got our match (or matches), we can use Notion’s test, replace, and replaceAll functions to do incredibly useful things with them.
Learn Regular Expressions
This page isn’t intended to be a full tutorial on writing regular expressions. It’s a reference on how to use them in Notion formulas, and on what particular regex characters are supported in Notion.
If you’re interested in learning regular expressions, here are a few resources I recommend:
- RegexOne – start here. This is the best beginner tutorial you’ll find.
- Regular-Expressions.info – a gold mine of regular expression tutorials and explanations.
- RexEgg – another fantastic general resource for learning regex.
- .Net Regular Expressions Quick Reference – intended for .NET developers, but still quite handy as a general resource.
- Regex101 – a tool for building and testing regular expressions.
Supported Regular Expression Characters
This section includes one or more examples for every regular expression feature supported within Notion’s formula editor.
See working examples for all of these features here:

Character Escapes
Working examples:

\u0000
– escaped Unicode reference
Code language: JavaScript (javascript)
\000
– octal character reference
Note: Only works in the regular expression argument. Doesn’t work in the input string or replacement string arguments.
Code language: JavaScript (javascript)
\x00
– hexadecimal character reference
Note: Only works in the regular expression argument. Doesn’t work in the input string or replacement string arguments.
Code language: JavaScript (javascript)
You can find a list of all Unicode, octal, and hexadecimal reference codes here:
\n
– new line
Code language: JavaScript (javascript)
There are also several characters that must escaped with single backslashes (\
) in order to be represented normally. These characters are used as special characters within regular expressions if they are not escaped.
Character | Escape |
---|---|
Period — . | \. |
Question mark — ? | \? |
Dollar sign — $ | \$ |
Asterisk — * | \* |
Plus sign — + | \+ |
Caret — ^ | \^ |
Left parenthesis — ( | \( |
Right parenthesis — ) | \) |
Left bracket — [ | \[ |
Right bracket — ] | \] |
Left curly brace — { | \{ |
Right curly brace — } | \} |
Pipe — | | \| |
Forward slash — / | \/ |
Backslash — \ | \\ |
Double quotations — " | \" |
Character Classes
Learn about character classes:
Working examples:

\w
– alphanumeric character
Notion considers non-spacing marks to be non-alphanumeric characters. Other regex engines (.NET, for example) do the opposite.
Lowercase letters | a-z |
Uppercase letters | A-Z |
Numbers | 0-9 |
Punctuation, Connector symbols | Notion only supports _ |
Code language: JavaScript (javascript)
\W
– non-alphanumeric character
Code language: JavaScript (javascript)
\d
– digit character (0-9)
Code language: JavaScript (javascript)
\D
– non-digit character
Code language: JavaScript (javascript)
\s
– whitespace character
Code language: JavaScript (javascript)
\S
– non-whitespace character
Code language: JavaScript (javascript)
.
– wildcard; matches any single character except newline (\n)
Code language: JavaScript (javascript)
[]
– character class (matches any single character included in the group)
Character classes support ranges such as A-Z
(all uppercase character), A-z
(all upper and lowercase characters), and 0-9
(all digits).
Commas may also be used to visually separate ranges and characters in your expression, but they are not needed.
Code language: JavaScript (javascript)
Character class subtraction is not supported.
[^]
– negated character class (matches any single character not included in the group)
Code language: JavaScript (javascript)
Quantifiers
Learn about quantifiers:
Working examples:

*
– match zero or more of the preceding element
Code language: JavaScript (javascript)
+
– match one or more of the preceding element
Code language: JavaScript (javascript)
?
– preceding element is optional; match it zero or one times
Code language: JavaScript (javascript)
??
– match preceding element zero or one times (as few times as possible)
Code language: JavaScript (javascript)
+?
– match preceding element one or more times (as few times as possible)
Code language: JavaScript (javascript)
*?
– match preceding element zero or more times (as few times as possible)
Code language: JavaScript (javascript)
{n}
– match the preceding element n times
Code language: JavaScript (javascript)
{n,}
– match the preceding element n or more times
Code language: JavaScript (javascript)
{n,m}
– match the preceding element between n and m times (inclusive)
Code language: JavaScript (javascript)
{n}?
– match the preceding element n times (no difference from {n}
Code language: JavaScript (javascript)
{n,}?
– match the preceding element at least n times, but as few times as possible
Code language: JavaScript (javascript)
{n,m}?
– match the preceding element at least n times, no more than m times, and as few times as possible
Code language: JavaScript (javascript)
Anchors
Learn about anchors:
Working examples:

^
– start of line
Code language: JavaScript (javascript)
$
– end of line
Code language: JavaScript (javascript)
\b
– word boundary
This is not a space (that’s \s
). This is the boundary between a word character and a non-word character (including punctuation such as ,
, .
, ;
, etc.). It is a zero-length match.
Code language: JavaScript (javascript)
\B
– not on a word boundary
Code language: JavaScript (javascript)
Character Grouping
Learn about character grouping and capturing:
Working examples:

()
– capture group (is automatically assigned a sequential reference number)
Code language: JavaScript (javascript)
(?<name>expression)
– named capture group
Code language: JavaScript (javascript)
(?:)
– non-capturing group
Code language: JavaScript (javascript)
Substitutions
Learn about substitutions:
Working examples:

$n
– capture group numbers
Code language: JavaScript (javascript)
$&
– copy of the whole match
Code language: JavaScript (javascript)
$`
– copy of the entire input string before the match
Code language: JavaScript (javascript)
$'
– copy of the entire input string after the match
Code language: JavaScript (javascript)
Backreferences
Learn about backreferences:
Working examples:

\n
– e.g. \1
– backreference. Must match an existing capture group
Note that the backreference looks for matches of the content of its capture group. It is not an alias for the expression within the capture group.
Code language: JavaScript (javascript)
(?<name>\w) \k<name>
– named backreference
Code language: JavaScript (javascript)
Alternation
Learn about alternations:
Working examples:

|
– either/or
Code language: JavaScript (javascript)
Lookarounds
Learn about lookarounds:
(?=) – Positive lookahead
The match must be followed by the regular expression in the lookahead.
Code language: JavaScript (javascript)
(?!) – Negative lookahead
The match must not be followed by the regular expression in the lookahead.
Code language: JavaScript (javascript)
(<?=) – Positive lookbehind
The match must be immediately preceded by the regular expression in the lookbehind.
Code language: JavaScript (javascript)
(<?!) – Negative lookbehind
The match must not be immediately preceded by the regular expresion in the lookbehind.
Code language: JavaScript (javascript)
Unsupported Features
The following features are currently not supported in Notion’s flavor of regex:
\A
\z
\Z
\p{name}
\P{name}
$+
$_
(?>*subexpression*)
(?(expression) yes | no)
- Flags/modifiers are not supported in Notion at all (so use lower or upper when needed).
Unicode Numbers in Regular Expressions
When writing regular expressions in Notion formulas, it is possible to “hard code” Unicode numbers into your expression. The regex engine will then parse these as their actual Unicode characters. (Thanks to Ben Borowski for pointing this out to me).
To do so, use double-backslashes \\
to escape the Unicode reference:
Code language: JavaScript (javascript)
See a working example of this:

It is also possible to use octal or hex codes here. For example:
Code language: JavaScript (javascript)
These \
Unicode references don’t work in input string argument, nor the replacement argument within replace and replaceAll. They’ll only be interpreted correctly within the regular expression argument.
Escaping Double Quotations
You can usually escape a double quotation "
in a Notion formula using a single backslash \
:
Code language: JavaScript (javascript)
This also works in the input-string and replacement arguments within Notion’s regular expression functions:
Code language: JavaScript (javascript)
However, this does not work inside of regular expressions – i.e., the second argument of the test, replace, and replaceAll functions.
Fortunately, you can get around this by hard-coding their Unicode character codes into your expression:
\u0022
for a normal quotation mark\u201c
for a left double quotation mark\u201d
for a right double quotation mark- For example, here’s how you could extract
"Iron Mike"
fromMike "Iron Mike" Tyson
:
Code language: JavaScript (javascript)
See a working example of this:

It’s best to ensure your character class includes all three common quotation marks: [\u0022\u201c\u201d]
When you type a quotation mark directly into the formula editor, you’ll get a normal quotation mark "
– however, when you type within text fields inside a Notion database, Notion intelligently uses left “
and right ”
quotation marks to wrap your text.
In the example above, I hard-coded Mike \"Iron Mike\" Tyson
within the formula editor. However, if that string had been pulled in via another property (e.g. prop("Name")
), then it would likely be using left “
and right ”
quotation marks.