View Single Post
Old Aug 5th, 2007, 2:43 PM   #1
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
POSIX compliant portable pathname

I haven't had much experience with regular expressions because I tend to avoid them like the plague. However, for this particular application it appeared to fit my needs well. In any case I wanted to create a function that would verify a pathname with the following structure:
whatever/whatever/whatever/........../whatever.php
It should follow the guidelines specified here, and my own stipulations:
  1. The pathname need not end in a filename
  2. If a filename is present it must end in '.php'
This was my solution:[PHP]preg_match('/^([a-z0-9_][a-z0-9\-_]*\/{1,1})*([a-z0-9_][a-z0-9\-_]*)*(\.php){0,1}$/iD', $text);[/PHP]Due to my inexperience I'd appreciate any regular expression gurus here on the forum highlighting where I might have missed something in my regular expression that would cause it to behave beyond the scope of the specified parameters. Thanks in advance for the help.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote