I have a URL:
www.domain.com/first/second/last/
How do I get the last term between slashes? i.e. last using regular expressions?
Please note that the URL could just be:
www.domain.com/last/
Or:
www.domain.com/first/second/third/fourth/last/
I need to extract this last term for use in the Zeus Server’s Request Rewrite module which uses PERL and REGEX.
Update
After implementing some answers, I have just realized that I need this match to be made only on URLs in a certain directory.
i.e.
www.domain.com/directory/first/second/last/
should return last. Whereas:
www.domain.com/first/second/last/
should not return a match.
Here’s a simple regex:
Should match anything you throw at it.
If you want to look in a particular directory, use this:
and your result will be in the first capture group.