Regular Expressions 101

Community Patterns

extract hostname

2

Regular Expression
PCRE (PHP <7.3)

/
^(?:http|ftp)s?:\/\/([\w][^\/=\s]+)\/?|(^w{3}[\.\w][^\/\=\s]{2,})\/?
/
mg

Description

extracts hostname from url

Submitted by Kristine Poghosyan - 8 years ago