tags:

views:

282

answers:

5

Hi, I'm a beginner in regexes. My requirement is to validate simple urls to urls with query strings, square brackets etc.. say for eg,

www.test.com?waa=[sample data]

the regex that I wrote only work for simple urls. It fails for the one with square brackets. Any idea?

+3  A: 

I would suggest taking a better look at the following site

http://www.regular-expressions.info/dotnet.html

Without actually seeing the Regex you're using I can't provide much insight. And giving you the answer wouldn't really teach you much either. Give a man a regex and you help him for a bit. Teach him regex and he's good for life

PSU_Kardi
thankx buddy.....
+1  A: 

Take a look at the following:

http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm

Brandon E Taylor
thanks a lot buddy!!!
+1  A: 

thanks a lot fr reply.. this is what i wrote ..works for query strings too...but it fails while adding []..

/^(https?|ftp):\/\/(?#)(([a-z0-9$_.+!*\'(),;\?&=-]|%[0-9a-f]{2})+(?#)(:([a-z0-9$.+!*\'(),;\?&=-]|%[0-9a-f]{2})+)?(?#)@)?(#)((([a-z0-9][a-z0-9-][a-z0-9].)(#)[a-z]{2}[a-z0-9-]a-z0-9|(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5].){3}(?#)(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])(?#))(:\d+)?(?#))(((\/+([a-z0-9$.+!*\'(),;:@&=-]|%[0-9a-f]{2}))*(?# )(\?([a-z0-9$.+!*\'(),;:@&=-]|%[0-9a-f]{2}))(?#)?)?)?(?#)(#([a-z0-9$.+!*\'(),;:@&=-]|%[0-9a-f]{2}))?(?#)$/i

My eyes! The goggles do nothing!
Sean Nyman
man, gotta love those regular expressions!
Hardwareguy
net.tcp://... is also a Uri, not covered by your Regex.
Nicolas Dorier
A: 

Hey Use this if u want url with http

http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=]*)?

if oyu dnt want http in URL then go for

?://([\w-]+.)+[\w-]+(/[\w- ./?%&=]*)?

+5  A: 

Do you really need to use regex ?

bool isUri = Uri.IsWellFormedUriString("http://...", UriKind.RelativeOrAbsolute)
Nicolas Dorier
Perfect answer for what I needed.
Dzejms