0

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?

1
  • 4
    posting the regex you wrote might have helped others in helping you; furthermore the web is full of examples, maybe a little research can just do Commented Jun 19, 2009 at 6:22

5 Answers 5

6

Do you really need to use regex ?

bool isUri = Uri.IsWellFormedUriString("http://...", UriKind.RelativeOrAbsolute)
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect answer for what I needed.
3

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

Comments

1

Take a look at the following:

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

Comments

1

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

2 Comments

My eyes! The goggles do nothing!
net.tcp://... is also a Uri, not covered by your Regex.
0

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- ./?%&=]*)?

Comments