Regular Expressions 101

Community Patterns

Extract domain and URI from an URL (no auth support)

0

Regular Expression
ECMAScript (JavaScript)

/
^(?:https?:\/\/)?([-\w.]+\.[\w]+){1}(\/[\/\d\w\.\-\?\+\&\#\=\~]*)?$
/
gi

Description

This regex is used to extract a domain name (including subdomains) and the full URI from a URL. will not match when credentials are provided in the url.

Submitted by anonymous - a year ago