Need routing help, specifically with regex

Hello! I'm building a directory with entries by state, county, and city. I've got the state and county working, but need some help with the city part of it. Here's my routing.

$route['insurance/([A-Z][A-Z])/(:any)'] = 'insurance/county/$1_$2';
$route['insurance/([A-Z][A-Z])/(:any)/(:any)'] = 'insurance/city/$1_$2_$3';

I'm guessing that the first (:any) is gobbling up the second. The ([A-Z][A-Z]) represents a state code.

It should go in this order:

Is there a regex that I can use instead of :any that excludes a forward slash? The only characters allowed should be A-Z, a-z, 0-9, and a dash (-) in the county or city.

Thanks for the help. If you need me to explain my question a little better, please just ask and I'll try to clarify.

Switch the routes so that the most specific route becomes the first and it will be fine

[A-Z][A-Z] can be written as [A-Z]{2}

The other regex you are looking for is [A-Za-z0-9\-]+

That did the trick! Thanks much.

Well if you really want any character except /n (newline) you could use (.+)

$route['insurance/([A-Z]{2})/(.+)'] = 'insurance/county/$1_$2';
$route['insurance/([A-Z]{2})/(.+)/(.+)'] = 'insurance/city/$1_$2_$3';

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.