Regular Expressions 101

Domain out of URL

Open Workspace
  • Golang
  • Match
0

Regular Expression

`
^(?:https?:)?(?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)
`
gm

Description

Regular expression ^(?:https?:)?(?://)?(?:[^@\n]+@)?(?:www.)?([^:/\n]+ ) used below extracts domain with subdomains out of a full url. It skips protocol (ex: https:), "//", "@", www subdomain and then captures everything (ex: domain) before ":" or "/" or end of line.

Submitted by Anonymous