Page 1 of 1

Pattern Conditionals -> Too Much?

Posted: Fri Feb 09, 2007 12:25 pm
by seodevhead
I am using mod_rewrite to rewrite some URL's for a database application. One of my URL's I am rewriting must start (after the base folder) with a folder named after one of the 50 U.S. states (ie. /alabama/, /alaska/, /arizona/, and so on.).

Is it okay to include all 50 of these state names within my RegEx pattern conditional? Or is that way too much info to put into a pattern and be too intensive?

Example:

Code: Select all

^/?(alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachussets|michigan|minnesota|mississippi|missouri|montana|nebraska|nevade|new-hampshire|new-mexico|new-york|north-carolina|north-dakota|ohio|oklahoma|oregon|pennsylvania|rhode-island|south-carolina|south-dakota|tennesee|texas|utah|vermont|virginia|washington|west-virigina|wisconsin|wyoming)/([a-zA-Z_]+)/([a-zA-Z_]+)$

Posted: Fri Feb 16, 2007 12:07 am
by Superman859
Try it and see. I imagine it will work, but may take a while to run depending on how many strings you run it through, etc.

It also depends on what kind of regex engine you are using, DFA or NFA. From what I understand, you're doing it in PHP so that would be NFA - it will be a slower match, since it will attempt basically every combination possible for letters without remembering anything.

Either way, it should work - try it out and see.

Posted: Fri Feb 16, 2007 12:14 am
by nickvd
Don't have a clue other than it would seem to be slower, but I don't know :)

I did notice a spelling mistake (I'm assuming you copy/pasted from your .htaccess file) s/nevade/nevada

And I'm a Canadian, eh? ;)

Posted: Fri Feb 16, 2007 3:29 am
by shwanky
I think you for got Purto Rico and Guam... I think that might be a bit much too much. Can't you create an error checking function using php or some other scripting language? if state not in array permanant error... or something to that extent?