Regular Expressions 101

Community Patterns

123...6

Community Library Entry

9

Regular Expression
Python

r"
^(http://|https://|http://www\.|https://www\.|www\.)?(www\.(twanda))?(([\w\-]+)?\.?(twanda|))(\.ch|\.com)(:\d+)?/.+$
"
igm

Description

This regex should extract the subdomain, if any, or the domain, if no subdomain is used, from an arbitrary URL

Submitted by trevi@twanda.com - 9 years ago