views:

72

answers:

2

I am implementing small url handler that will need to match the following (assuming each one would be a separate regex).

http://mysite.com/products/could/be/this/long.aspx http://mysite.com/search.aspx OR /search/keyword1+keyword2.aspx (only need to know that search is in the first part) http://mysite.com/somename/products/could/be/this/long.aspx (need to know that the second is products)

Thinking of non-regex, would it be simpler and quicker to split the url and check that way?

EDIT:

I have to do a hybrid now. I am splitting for the url handler, but further down the track, I can only use regex, however it alot simpler.

The two rules I need to check for are:

http://mysite.com/products/somename.aspx

http://mysite.com/name/products/somename.aspx

The check is that products is in the first section, with a dynamic name in the second, OR that a dynamic name, followed by products, followed by dynamic name.

+2  A: 

Yes. Don't use regex. Split.

Noon Silk
I'm doing something different, but that is very good advice! +1
IainMH
A: 

Are you just looking for a regex to match a URL with "products" as the first or second component in its file path portion?

string regex = @"http://mysite.com/(?:\w+/)?products/";
Alan Moore