← Back to Notion formulas
URLsBeginner

Notion Formula to Extract a Domain from a URL

Copy a Notion formula that removes the protocol, www prefix, and path from a URL to keep only its domain.

Notion Formula to Extract a Domain from a URL cover

Use case

Extract a clean domain from a URL

Properties

URL

Use this formula to turn URLs such as https://www.example.com/articles/notion into a clean domain such as example.com.

if(
  empty(prop("URL")),
  "",
  replaceAll(
    replaceAll(
      replaceAll(prop("URL"), "https?://", ""),
      "^www\\.",
      ""
    ),
    "[/?#].*",
    ""
  )
)

What this formula does

StepResult
Remove http:// or https://www.example.com/articles
Remove www. at the startexample.com/articles
Remove the path, query, or fragmentexample.com

The formula uses regular expressions in replaceAll(). It also returns a blank value when the URL property is empty.

Database setup

Create these properties in your Notion database:

PropertyTypeExample
NameTitleNotion Formula Guide
URLURLhttps://www.example.com/guide?ref=notion
DomainFormulaThe formula above

If your URL property is named Website, replace prop("URL") with prop("Website").

Keep the www prefix

If you want www.example.com instead of example.com, remove the second replaceAll() call:

if(
  empty(prop("URL")),
  "",
  replaceAll(
    replaceAll(prop("URL"), "https?://", ""),
    "[/?#].*",
    ""
  )
)

Extract the registered domain only

This formula keeps the last two domain parts for common domains:

replaceAll(prop("URL"), ".*?([a-z0-9-]+\\.[a-z]{2,})([/\\?#].*)?$", "$1")

Use this variant carefully. Country-code domains such as example.co.uk and multi-level domains may need custom handling.

Common problems

If the path is still visible, check that the URL contains a slash, question mark, or hash after the domain and that the formula was pasted without changing the backslashes.

If www is still visible, make sure the URL starts with www.. The formula only removes that prefix at the beginning of the value.

This formula cleans the text; it does not validate whether the URL is reachable or correctly formatted.