seodevhead Posted February 11, 2007 Share Posted February 11, 2007 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: ^/?(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_]+)$ Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 That amount of alternation is not ideal at all. Can you use their abbreviations? If you must use the names, you should be able to condense the pattern a little, but it would still be a lot of work. For instance, (alabama|alaska) can be reduced to (ala(?:bama|ska)), which will prevent backtracking and reanalyzing 3 characters. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.