Solved

foxpro - finding domain name within URL with Regular Expressions

Posted on 2013-11-05
3
857 Views
Last Modified: 2013-11-07
Yesterday pcelba posted the exact code that I needed to find all email addresses in text:

www.experts-exchange.com/Microsoft/Applications/FoxPro/Q_28284572.html (see last reply in solution)

I'm going to use the same code for extracting the domain name from a URL, but don't know what regular expression pattern that I need.

eg.
from "www.google.com"
to extract 'google'

or

from "https://secure.experts-exchange.com""
to extract "experts-exchange"

I've tried various patterns found here:
http://stackoverflow.com/questions/569137/how-to-get-domain-name-from-url

but they don't seem to work in Foxpro with the code in the answer from yesterday.
Does anyone have a tried and tested pattern that works?
0
Comment
Question by:esak2000
3 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 167 total points
ID: 39623888
If you have URL already then you don't need RegExp to extract the domain name BUT you have to define what "domain" means for you... (It is stated in the StackOverflow already)

www.google.com ... google
www.celba.cz  ... celba
celba.cz  ... celba

that was easy... but

www.abc.co.uk ... co   or   abc.co   or   abc ?
etc.

And what about visualfoxpro.application etc ?

So you'll need to distinguish between domains and e.g. OLE class names as the above one and also other similar elements... and their names can be very similar if not equal to domains.

To define a list of TLDs or domain suffixes is good idea probably.

And to do the whole task you just need STREXTRACT() or AT() and SUBSTR() functions in FoxPro.
0
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 167 total points
ID: 39623981
Pavel has got the main point, there are much more top level domains and more are coming. I don't see that as a task for regexp anymore, too complicated.

Looking at http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax
What you want to extract is only the second level domain part of the host name without the top level domain.

The same second level domain combined with other top level domains may be interesting for domain grabbers or researches for a potential product name, etc.

So there is use for extracting that info, but another top level domain normally means another hoster, maintainer, owner, service, brand, market, etc. Only the full hostname SLD.TLD is techncally relevant and stands for an IP (or a series of IPs related to the same host). Being able to extract or stripe off a subdomain is perhaps more important.

I'd let DNS do that for me. Extract the part between : and the first following / and see what IP you get from DNS, repeat with partial names. The shortest name giving you the same IP from DNS is the hostname, and the last part(s) of that is/are a TLD.

Bye, Olaf.
0
 
LVL 9

Assisted Solution

by:Derek Jensen
Derek Jensen earned 166 total points
ID: 39624832
The most common/useful regexp I usually use for locating a URL goes something like this:

/https?:\/\/(\w*\.?[^\/]+?\.\w{2,3})/

Open in new window

But as for grabbing the rest of the URL, I'll have to defer to prior experts' comments. :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now