Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: HackneyCabPosted on 2006-10-05 at 06:42:08ID: 17668404
Well, I thought a pattern like this might work:
hree/four/ five/
^([^/]+/){0,8}([^/]+/?)$
(I'm using .htaccess, so my slashes may be on the opposite side to yours).
Unfortunately, the variable-occurrence term (marked by {0,8} allowing zero to eight occurrences), only seems to capture the final matching occurrence. So a request for:
http://127.0.0.1/one/two/t
was only returning $1 as four/ and $2 as five/ which is obviously of no use. I don't know of any way to alter this behaviour from the pattern matcher.
So I recommend just capturing the lot, and then using a Java method to split the captured string by forward slashes. PHP has a function called explode, but I'm not sure what Java's equivalent might be. It will mean a bit more effort.
The alternative is to write out a rule for each possibility. Not a pretty solution, but that ought to work too.