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:
- The pathname need not end in a filename
- 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.