Pattern Conditionals -> Too Much?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Pattern Conditionals -> Too Much?

Post 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_]+)$
Superman859
Forum Commoner
Posts: 47
Joined: Sun Oct 29, 2006 10:22 am

Post 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.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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? ;)
shwanky
Forum Commoner
Posts: 45
Joined: Thu Feb 15, 2007 1:21 am

Post 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?
Post Reply