tags:

views:

191

answers:

4

Can someone write a regex that can match only lowercase urls that can have a-z letters, 0-9 numbers and -, http:// (https is not required), www. and doesn't have default.aspx?

This is a url that regex must match:
http://www.somedomain.net/news/148/some-text-to-act-as-news-title.aspx

or

http://subdomain.somedomain.net/news/148/some-text-to-act-as-news-title.aspx (withour www.)

Regex must not match any url that have uppercase letters and default.aspx

I did some basic regex that match some of the urls.

Thank you.

EDITED


This is my attempt: [a-z0-9]{1,}-*

Only matches single words, words with - and numbers

EDITED AGAIN


Thanks guys to all of you.

+2  A: 
^http://((?!default\.aspx)[a-z0-9\-\./])*$
Lucero
A: 

you should exclude the urls that have Uppercase and default.aspx with your native lang. but if you want everything BUT the caps do this.

[a-z/- 0-9]*
Keng
Why using the native lang? Regex is perfect for exaclty such pattern matching...
Lucero
the general rule for regex is if you have a search function in the native language that can do something easily it usually faster than regex. if you just want to say, "skip this line if it has an UC char", that will most likely be faster in the NL.
Keng
+2  A: 
^http://[a-z0-9.-]+\.[a-z0-9]+(/(?!.*default\.aspx)[a-z0-9./-]+)?$
chaos
You made the same typo as I did, you need to escape the dot in default.aspx and I'd suggest escaping it in the [] also ;)
Lucero
+2  A: 

A solution with look-ahead assertion:

^http://[a-z0-9-.]+(?:(?!/default\.aspx)/[a-z0-9-.]+)*$
Gumbo