• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

Regular Expressions - web address

Hello Experts,

I need a regular expression that'll check for a valid web address, but it needs to be very ... accepting.  Essentially, anything should match as follows:

1) Must begin with http://
2) Must alllow for any amount of these characters:   / - _?=&
3) Must contain letters
4) 1 to x periods are required

That's it, if anyone can whip me up an expression I've be grateful ... sadly I'm Reg Ex challenged.

Thanks,
Moe
0
mauricerichard
Asked:
mauricerichard
  • 5
  • 4
1 Solution
 
petr_hlucinCommented:
a) Why don't use use one of many RegExes for URL validating on the Internet (e.g. http://snippets.dzone.com/posts/show/452)?

b) The RegEx you describe should look like the following one (except for 4) which I don't understand). Maybe you should also add numeric values.
http://[a-z.]+[a-z/-?=&]*

Open in new window

0
 
mauricerichardAuthor Commented:
Hi Petr,

Thanks for the RegEx.  I tried many, many RegEx snippets online but they werern't validating correctly for me.  We have some oddball URLs, and I've been asked to make validation very forgiving.

#4 meant that one period was required, but it wasn't limited to one period.

Thanks,
Moe
0
 
mauricerichardAuthor Commented:
Hi Petr,

It would seem that the hyphen character is causing this validation to fail.
Not sure why, as I see it in the Reg Ex.  Any thoughts on how to fix this?

Thanks,
Moe
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
petr_hlucinCommented:
Sorry, I forgot that hyphen is a special char in RegEx - use escape sequence as shown in the attached code snippet.
http://[a-z.]+[a-z/\-?=&]*

Open in new window

0
 
mauricerichardAuthor Commented:
Hi Petr,

No worries, I'm just glad to be getting some help on this.  The above RegEx seems to be failing altogether.  Let me give you two examples of URLs I'm using for testing.

ex1: http://website.subsite.k-sites.com/
ex2: Http://server/folder/webpage.aspx?ID=716&TEL=555-666-7777

I appreciate the help, I've been at this for hours and I'm entirely frustrated.
0
 
petr_hlucinCommented:
Let's expand it for numerics and uppercase.
[hH][tT][tT][pP]://[a-zA-Z0-9.]+[a-zA-Z0-9./\-?=&]*

Open in new window

0
 
mauricerichardAuthor Commented:
You sir, are brilliant.  This mostly works now.

All that is left is to ensure that a minimum of one period is used, and that some letters are typed as well.  Is that difficult?
0
 
petr_hlucinCommented:
What do you mean by period? If you mean part of the string in front of the first "/" (disregarding "http://") then use this one. It solves the miminum of some letter behind "http://".
[hH][tT][tT][pP]://[a-zA-Z0-9.\-]+/[a-zA-Z0-9./\-?=&]*

Open in new window

0
 
mauricerichardAuthor Commented:
By period I mean dot ... as in: .com

But you've given me more than enough to work with here, I should be able to muddle through the rest.  Thanks a million for the help!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now