Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / domain regex expressions

Author
Message
Epimetheus
20
Years of Service
User Offline
Joined: 5th Oct 2003
Location: Naples, Florida
Posted: 9th Jun 2014 04:31 Edited at: 9th Jun 2014 08:16
I trying to create a regex that can extract the base domains from various lines of strings that may contain 1 or multiple domains e.g.



should return:



I have an expression that seems to work (but only returns the first domain in a line):



It would be nice to keep it clean of other strings that end with 3 letter extensions like register.php but that is not required. It would also be good to keep it as simple and fast as possible.

Also it should be able to sub domains and country specific domains e.g. mysubdomain.website.co.uk, Any ideas?
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 9th Jun 2014 06:02
Hmm regex huh? What language is this written in? I would probably shy away from regex. As the saying goes:

Quote: "Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. "


I would instead find the first occurrence of a valid TLD that I want, then move backwards on the string until I hit an invalid character. As long as I had at least one valid character before the TLD, that's a good domain, then move onto the next found tld in the string.

Login to post a reply

Server time is: 2024-04-23 15:30:00
Your offset time is: 2024-04-23 15:30:00