mauricerichard
asked on
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
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
ASKER
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
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
ASKER
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
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
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/\-?=&]*
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
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!
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!
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.
Open in new window