I have an expression that will grab the domain (xxx.com) out of a url (http://www.google.com/?query=blah).

Requirements: 1) Must be able to work if there is a port number in the URL (http://www.amazon.com:8010/somepage.html) 2) Needs to get the domain (something.com) part (preferably into 1 variable, but if it's in 2 I can join them) 3) Needs to work if the URL does not contain stuff between the domain and '://' (http://somesite.com/page.html) 4) Needs to work if the URL has a lot of subdomains (http://some.domain.some.other.domain.site.com/page.htm)

My current expression sometimes doesn't work, but I'm not sure if if is one of the above conditions or something else.

It's a bit more than I need, but wow. I can dissect most of it but I need to look at it longer to understand it all. ---------- The vastness of what we know is only surpassed by the vastness of what we don't.

NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- m, 'm,' ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- [^:/?#]+ any character except: ':', '/', '?', '#' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- : ':' ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- // '//' ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- [^/?#]* any character except: '/', '?', '#' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- ( group and capture to \3: ---------------------------------------------------------------------- [^?#]* any character except: '?', '#' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \3 ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- \? '?' ---------------------------------------------------------------------- ( group and capture to \4: ---------------------------------------------------------------------- [^#]* any character except: '#' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \4 ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- # '#' ---------------------------------------------------------------------- ( group and capture to \5: ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \5 ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- , ',' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

That actually makes sense to me after reading through it with a nice explanation, lol. ---------- The vastness of what we know is only surpassed by the vastness of what we don't.