Gossamer Forum
Home : General : Perl Programming :

URL regex

Quote Reply
URL regex
I don't want to start off another of those regex wars but I was trying to come up with something to match URL's properly, or at least to a certain degree....this is what I came up with:

Code:
m|^http://(?:[a-z0-9-]+\.)?[a-z0-9-]+\.[a-z]+(?:\.[a-z]+)?$|i

Can anyone see any obvious problems with it?

Last edited by:

Paul: Aug 8, 2002, 6:44 AM
Quote Reply
Re: [Paul] URL regex In reply to
Underscores?
Quote Reply
Re: [giovanni] URL regex In reply to
Underscores aren't valid in domain names are they?
Quote Reply
Re: [Paul] URL regex In reply to
Well are you talking about an "URL" as your post title indicates or a domain name? :-)

- wil
Quote Reply
Re: [Wil] URL regex In reply to
Well I thought it would be fairly obvious from the regex I'm talking about a domain name. It would be a pretty crap regex if I was trying to match things like:

http://www.123domain.com/~foo/cgi-bin/secret_location/index1.html

Tongue
Quote Reply
Re: [Paul] URL regex In reply to
Foriegn character domain names?

http://nunames.nu/eu-lang-test.htm

Last edited by:

Aki: Aug 8, 2002, 8:23 AM
Quote Reply
Re: [Aki] URL regex In reply to
ewwwwww Frown
Quote Reply
Re: [Paul] URL regex In reply to
In Reply To:
Underscores aren't valid in domain names are they?
Blush
Quote Reply
Re: [Paul] URL regex In reply to
Maybe this helps:

http://www.ietf.org/rfc/rfc2396.txt

Your regex doesn't support ftp, gopher and other protocols, obviously.

Can I ask what is the point of the exercise, and why you're not using a module?

- wil
Quote Reply
Re: [Wil] URL regex In reply to
>>>and why you're not using a module? <<<

LOL...Wil's back with his Modules Tongue

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!