Welcome Guest, Not a member yet? Register   Sign In
Need routing help, specifically with regex
#1

[eluser]ehicks727[/eluser]
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.

Code:
$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:
insurance/statecode/county
or
insurance/statecode/county/city

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.
#2

[eluser]xwero[/eluser]
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\-]+
#3

[eluser]ehicks727[/eluser]
That did the trick! Thanks much.
#4

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

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




Theme © iAndrew 2016 - Forum software by © MyBB