RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Specific Top-Level Domain (TLD)
Expression
^.*(yourdomain.com).*$
Description
Matches the TLD of a given domain (replace yourdomain.com with whatever domain you're trying to enforce). I was writing an web application in which I wanted to to display a special message to visitors if and only if they were referred to my site by one specific site. However, because the specific site in question was highly dynamic, referring URLs were all over the place in terms of consistency and the only thing I knew I could count on 100% was the TLD (subdomains and file paths acceptable, so long as the TLD matches exactly).
Matches
yourdomain.com | http://www.yourdomain.com | http://subdomain.yourdomain.com/pages/manage/?act=4015876&ag=709254588456a
Non-Matches
your-domain.com | ourdomain.com | yourdomain.co
Author Rating: The rating for this expression. Matt Finazzo
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Specific Top-Level Domain (TLD)
Name: Paul Randall
Date: 4/24/2008 10:25:30 AM
Comment:
Besides yourdomain.com, it matches yourdomainXcom, yourdomainYcom, and yourdomainZcom and a host of similar strings. Escaping the period, so the regex becomes ^.*(yourdomain\.com).*$ fixes the problem.


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials