Regular Expression – Extract subdomain & domain

Your regex doesn’t seem correct. Try this regex:

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

RegEx Demo

Leave a Comment