R
richardlev
Hi all,
I'm trying to create a regular expression to go up one directory,
sorta.
Another way of saying would be to remove the trailing part of the path
(with the caveat that /index.php is treated as /).
Perhaps some examples would be better:
/foo/bar/index.php -> /foo/
/foo/bar/ -> /foo/
/foo/bar/somepage.php -> /foo/bar
Basically, i want to treat / and /index.php as the same thing, which
would mean 'remove the trailing directory,' while at the same time
saying 'if i'm looking at a file in this directory, remove the file and
look at this directory.' The idea being, headers on pages go up one
logical layer.
about to make a post -> view forum listing
/forum/post.php -> /forum/
viewing the forum listing -> viewing main website index
/forum/ -> /
/forum/index.php -> /
I hope that makes sense.
Everytime i try to make a regex i always run into the problem of it
treating 'index.php' as 'any other string'
ie: .+((/.+/index.php)|(/.+))$
That last /.+ is causing /foo/bar/index.php to match the trailing
/index.php
All the other approaches i've tried leave me with this same basic
problem and a regex similar to the above.
Any help would be appreciated.
-Richard Levasseur
I'm trying to create a regular expression to go up one directory,
sorta.
Another way of saying would be to remove the trailing part of the path
(with the caveat that /index.php is treated as /).
Perhaps some examples would be better:
/foo/bar/index.php -> /foo/
/foo/bar/ -> /foo/
/foo/bar/somepage.php -> /foo/bar
Basically, i want to treat / and /index.php as the same thing, which
would mean 'remove the trailing directory,' while at the same time
saying 'if i'm looking at a file in this directory, remove the file and
look at this directory.' The idea being, headers on pages go up one
logical layer.
about to make a post -> view forum listing
/forum/post.php -> /forum/
viewing the forum listing -> viewing main website index
/forum/ -> /
/forum/index.php -> /
I hope that makes sense.
Everytime i try to make a regex i always run into the problem of it
treating 'index.php' as 'any other string'
ie: .+((/.+/index.php)|(/.+))$
That last /.+ is causing /foo/bar/index.php to match the trailing
/index.php
All the other approaches i've tried leave me with this same basic
problem and a regex similar to the above.
Any help would be appreciated.
-Richard Levasseur