<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5f290176-d74d-4847-824b-f173f3489a87/tfexplains-profile.jpg" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5f290176-d74d-4847-824b-f173f3489a87/tfexplains-profile.jpg" width="40px" /> This page contains working examples for all supported character classes in Notion regular expressions. Duplicate this page to your workspace if you’re unable to view the formulas.

Regular Expressions in Notion Formulas

Created by Thomas Frank | Learn Notion Formulas | Notion Basics | Templates | Twitter

</aside>

πŸ“š References:


Character Escapes

Character Classes

Quantifiers

Anchors

Character Grouping

Substitutions

Backreferences

Alternation


Unicode Numbers in Regular Expressions


Regular Expression Examples


Notion Formula Examples


πŸ“œ Table of Contents:


\\\\w - alphanumeric character

<aside> πŸ’‘ Notion considers non-spacing marks to be non alphanumeric characters. Other regex engines (.NET, for example) do the opposite.

</aside>

Lowercase letters a-z
Uppercase letters A-Z
Numbers 0-9
https://www.fileformat.info/info/unicode/category/Pc/list.htm Notion only supports _
replaceAll("CAPS_nocap 12345", "\\\\w", "*")
// Output: ********** *****

Test

\\\\W - non-alphanumeric character

replaceAll("correct horse battery staple", "\\\\W", "")
// Output: correcthorsebatterystaple

Test

\\\\d - digit character (0-9)

replaceAll(id(), "\\\\d", "")
// Output: ddecdfeacb (where ID is dd68e1cdf20e4000962a0583cb007342)

Test

\\\\D - non-digit character

replaceAll(id(), "\\\\D", "")
// Output: 1226438582411837830594 (where ID is 122643c8582b4c1183bccfe783e05f94)

Test

\\\\s - whitespace character

replaceAll("charmander man bun", "\\\\sman\\\\s", " ")
// Output: charmander bun

Test

\\\\S - non-whitespace character

replaceAll("charmander man bun", "\\\\Sman\\\\S", "ndl")
// Output: chandler man bun

Test

. - wildcard; matches any single character except newline (\\\\n)

replaceAll("And blimey, if it ain't mutton again today!", ".", "😑")
// Output: 😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑

// Include newlines using (.|\\\\n)
// Assume prop "TwoLines" contains:
    // And blimey,
    // if it ain't
    // mutton again today!
replaceAll(prop("TwoLines"),"(.|\\\\n)","😑")
// Output: 😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑😑

Test

[] - character class (matches any single character included in the group)

replaceAll("gold fold bold","[gfb]","t")
// Output: told told told

replaceAll("27 dresses","[a-z]","πŸ‘—")
// Output: 27 πŸ‘—πŸ‘—πŸ‘—πŸ‘—πŸ‘—πŸ‘—πŸ‘—

replaceAll("abcdefghijklmnopqrstuvwxyz123456789", "[a-ev-z1357-9]", "πŸ™„")
// With commas:
replaceAll("abcdefghijklmnopqrstuvwxyz123456789", "[a-e,v-z,1,3,5,7-9]", "πŸ™„")
// Output: πŸ™„πŸ™„πŸ™„πŸ™„πŸ™„fghijklmnopqrstuπŸ™„πŸ™„πŸ™„πŸ™„πŸ™„πŸ™„2πŸ™„4πŸ™„6πŸ™„πŸ™„πŸ™„

Test

[^] - negated character class (matches any single character not included in the group)

replaceAll("123456789abcdefghijklmnopqrstuvwxyz", "[^a-z]", "")
// Output: abcdefghijklmnopqrstuvwxyz

replaceAll("abcdefghijklmnopqrstuvwxyz123456789", "[^cow]", "")
// Output: cow ("c","o","w" are in alphabetical order naturally. The character class doesn't specificy order.)

Test


Β© Thomas Frank