Regex To Extract Filename & Domain Name From URL

A regular expression to extract the filename or domain name from a given URL (after the /, before the file extension).

Can be used to get all filenames or domain names from a list of URLs.

/^.*\/|\.[^.]*$/g

Matches:

  • https://regexpattern.com
  • https://www.regexpattern.com
  • https://www.regexpattern.com/example.jpg
  • https://regexpattern.com/path/admin.php

See Also:

Regex Is Copied!