Regular Expression – Extract subdomain & domain August 10, 2023 by Tarik Your regex doesn’t seem correct. Try this regex: /^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img RegEx Demo